Skip to content

Commit 95a74c5

Browse files
small code changes
1 parent 896f09d commit 95a74c5

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
8+
## [1.6.6] - 2026-04-07
99
### Added
1010
- Added configurable file contents size limit (`SCANOSS_FILE_CONTENTS_LIMIT`).
1111
- Limits the maximum file size returned by the `file_contents` endpoint (default: 50 MB).
12-
- Returns HTTP 400 when the file exceeds the configured limit.
12+
- Returns HTTP 400 with the error `file contents size exceeds` when the file exceeds the configured limit.
1313

1414
## [1.6.5] - 2026-03-26
1515
### Fixed

pkg/service/filecontents_service.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ func (s APIService) FileContents(w http.ResponseWriter, r *http.Request) {
8282
http.Error(w, "ERROR recovering file contents", http.StatusInternalServerError)
8383
return
8484
}
85+
// convert the configured limit from MB to bytes.
8586
limitBytes := s.config.Scanning.FileContentsLimit * 1024 * 1024
87+
outputLen := int64(len(output))
8688
// unlimited for FileContentsLimit <= 0
87-
if limitBytes > 0 && int64(len(output)) > limitBytes {
88-
zs.Warnf("File contents size %d bytes exceeds limit %d MB for md5 %s", len(output), s.config.Scanning.FileContentsLimit, md5)
89+
if limitBytes > 0 && outputLen > limitBytes {
90+
zs.Warnf("File contents size %d bytes exceeds limit %d MB for md5 %s", outputLen, s.config.Scanning.FileContentsLimit, md5)
8991
w.Header().Set(ContentTypeKey, ApplicationJSON)
9092
w.WriteHeader(http.StatusRequestEntityTooLarge)
9193
resp := map[string]string{
@@ -97,13 +99,13 @@ func (s APIService) FileContents(w http.ResponseWriter, r *http.Request) {
9799
}
98100
charset := detectCharset(output)
99101
if s.config.App.Trace {
100-
zs.Debugf("Sending back contents: %v - '%s'", len(output), output)
102+
zs.Debugf("Sending back contents: %v - '%s'", outputLen, output)
101103
} else {
102-
zs.Debugf("Sending back contents: %v", len(output))
104+
zs.Debugf("Sending back contents: %v", outputLen)
103105
}
104106
w.Header().Set(ContentTypeKey, fmt.Sprintf("text/plain; charset=%s", charset))
105107
w.Header().Set(CharsetDetectedKey, charset)
106-
w.Header().Set(ContentLengthKey, fmt.Sprintf("%d", len(output)))
108+
w.Header().Set(ContentLengthKey, fmt.Sprintf("%d", outputLen))
107109
printResponse(w, string(output), zs, false)
108110
}
109111

0 commit comments

Comments
 (0)