embeddedfs/vmdk: limit zlib grain decompression to prevent memory exhaustion#1993
Open
adilburaksen wants to merge 2 commits intogoogle:mainfrom
Open
embeddedfs/vmdk: limit zlib grain decompression to prevent memory exhaustion#1993adilburaksen wants to merge 2 commits intogoogle:mainfrom
adilburaksen wants to merge 2 commits intogoogle:mainfrom
Conversation
…austion A stream-optimized VMDK grain whose compressed payload decompresses beyond one grain size (grainBytes) caused io.ReadAll to allocate unbounded memory. A 512 KB crafted .vmdk could trigger ~1.7 GB of heap allocation with no error returned to the caller. Fix: replace io.ReadAll(zr) with io.ReadAll(io.LimitReader(zr, grainBytes+1)) and return an error if the decompressed output exceeds the expected grain size. Add TestConvertVMDKZlibBombRejected to confirm the bomb is rejected.
…) (errcheck/gofmt/usetesting)
Author
|
Hi! Just a friendly ping — all CI checks are passing. Happy to address any review feedback whenever you get a chance. Thanks for your time! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
convertStreamOptimizedExtentcallsio.ReadAllon a zlib reader forcompressed grains with no decompression size limit. A crafted
stream-optimized VMDK with a single grain whose payload compresses at
~1000:1 ratio (e.g., zeros) causes ~1.7 GB of heap allocation from a
512 KB input file. The function returns
nilon success, making thememory spike silent.
Root cause (
vmdk.go:320, before this fix):```go
dec, derr := io.ReadAll(zr) // no size limit
```
The
else if size < uint32(grainBytes) || size > uint32(grainBytes)branch is equivalent to
size != grainBytesand triggers for allcompressed grains, which is the normal case in stream-optimized VMDKs.
Fix
Replace
io.ReadAll(zr)withio.ReadAll(io.LimitReader(zr, grainBytes+1))and return an error if the decompressed data exceeds the expected grain size.
A valid compressed grain decompresses to exactly
grainBytes; anything largerindicates a malformed or malicious file.
Testing
TestConvertVMDKZlibBombRejectedcrafts a minimal malicious VMDK in pure Go(1 MB of zeros compressed to ~1 KB, far exceeding
grainBytes = 65536) andconfirms the fixed code returns an error rather than allocating memory.
Before fix:
TotalAlloc delta: 1735 MBfrom a 512 KB file.After fix:
TotalAlloc delta: 0 MB, immediate error returned.