From 2c165a632c61b56d76cf095f707cdbe8d804ac51 Mon Sep 17 00:00:00 2001 From: Ben McClelland Date: Wed, 1 May 2024 09:30:08 -0700 Subject: [PATCH] fix: int overflow check in chunk reader Make the code scanners happy with a bounds check before we do the integer conversion from int64 to int, since this can overflow on 32 bit platforms. Best error to return here is a signature error since this is a client problem and the chunk headers are considered part of the request signature. --- s3api/utils/chunk-reader.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/s3api/utils/chunk-reader.go b/s3api/utils/chunk-reader.go index c75b868..918d143 100644 --- a/s3api/utils/chunk-reader.go +++ b/s3api/utils/chunk-reader.go @@ -23,6 +23,7 @@ import ( "fmt" "hash" "io" + "math" "strconv" "time" @@ -192,6 +193,9 @@ func (cr *ChunkReader) parseAndRemoveChunkInfo(p []byte) (int, error) { cr.chunkDataLeft = 0 cr.chunkHash.Write(p[:chunkSize]) n, err := cr.parseAndRemoveChunkInfo(p[chunkSize:n]) + if (chunkSize + int64(n)) > math.MaxInt { + return 0, s3err.GetAPIError(s3err.ErrSignatureDoesNotMatch) + } return n + int(chunkSize), err }