qcow2-rs: fix(meta): Prevent panic on malformed qcow2 header #8
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.
A malformed qcow2 header with an invalid cluster_bits value could cause a panic due to a left-shift overflow when calculating the cluster size. This could be triggered by a crafted qcow2 image, leading to a denial of service.
This commit fixes the issue by validating the cluster_bits field before it is used. The value is now checked to be within a valid range (9 to 30, inclusive) to prevent the overflow. If the value is out of range, the header parsing function now returns an error instead of panicking.
A test case with a known malformed header has been added to ensure this vulnerability does not regress.