@@ -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