Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix header length handling (again) #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

niklasha
Copy link

Revert the last change to the header length check. Properly skip any additional fields, and make the correct check, also remove an entirely bogus check.This is tested, with both the test image in the tests/ directory, as well as newly created images by qemu-img (6.2) on both MacOS and OpenBSD, according to this vasi/qcow2-fuse#4

niklas added 2 commits February 14, 2022 10:42
…oblem was that additional fields was not handled at all. Do this handling and check the header length properly. Also, remove an entirely bogus check.
@@ -246,6 +246,11 @@ impl Header {
self.v3.autoclear.set(try!(io.read_u64()));
self.v3.refcount_order = try!(io.read_u32());
self.v3.header_length = try!(io.read_u32());
if self.v3.header_length as u64 > io.position() {
// There are addition fields.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

additional please

self.v3.header_length)));
}
if actual_length != HEADER_LENGTH_V3 as u64 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should get rid of the constant too?

@@ -268,16 +273,11 @@ impl Header {
if self.v3.refcount_order > 6 {
return Err(Error::FileFormat(format!("bad refcount_order {}", self.v3.refcount_order)));
}
if self.v3.header_length as u64 != io.position() {
if self.v3.header_length as u64 != actual_length {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this check is actually useful. We're setting position to header_length, storing that, and then checking if it's what we set it to. Of course it is!

Maybe instead we can check if the length matches the spec? https://github.com/qemu/qemu/blob/master/docs/interop/qcow2.txt#L184-L185

Copy link
Owner

@vasi vasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the submission, I think it's on the right track!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants