Skip to content

Commit 3056dd5

Browse files
committed
Fix zero-detection loop panic on non-block-aligned writes
Prevents index-out-of-range panic in WriteAtWithoutLock when buffer length is not a multiple of blockSize by computing the actual slice end for each block iteration.
1 parent fa24b44 commit 3056dd5

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

  • packages/orchestrator/pkg/sandbox/block

‎packages/orchestrator/pkg/sandbox/block/cache.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ func (c *Cache) WriteAtWithoutLock(b []byte, off int64) (int, error) {
348348
// detect-zeroes=unmap: route aligned all-zero blocks to Empty.
349349
for i := off; i < end; i += c.blockSize {
350350
idx := uint32(header.BlockIdx(i, c.blockSize))
351-
if header.IsZero(b[i-off : i-off+c.blockSize]) {
351+
blockEnd := min(i-off+c.blockSize, int64(len(b)))
352+
if header.IsZero(b[i-off : blockEnd]) {
352353
c.punchHole(i, c.blockSize)
353354
c.tracker.SetRange(idx, idx+1, Zero)
354355
} else {

0 commit comments

Comments
 (0)