Skip to content

Commit

Permalink
Add additional checks in chunking functionality (#671)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhurley authored May 9, 2024
1 parent fa55e63 commit a498a43
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
15 changes: 14 additions & 1 deletion sdk/checksum/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,26 @@ func HexChecksum(b []byte) string {
// Chunk - split bytes to chunk limits
func Chunk(buf []byte, lim int) [][]byte {
var chunk []byte
chunks := make([][]byte, 0, len(buf)/lim+1)
bufSize := len(buf)

if bufSize == 0 {
return [][]byte{}
}

if bufSize <= lim {
return [][]byte{buf}
}

chunks := make([][]byte, 0)

for len(buf) >= lim {
chunk, buf = buf[:lim], buf[lim:]
chunks = append(chunks, chunk)
}

if len(buf) > 0 {
chunks = append(chunks, buf[:])
}

return chunks
}
1 change: 1 addition & 0 deletions sdk/checksum/checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestHexChunk(t *testing.T) {
expected: [][]byte{},
},
}

for _, test := range tests {
result := Chunk(test.input, test.limit)
assert.Equal(t, test.expected, result)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion vendor/github.com/nginx/agent/sdk/v2/checksum/checksum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a498a43

Please sign in to comment.