-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: master
Are you sure you want to change the base?
Conversation
This reverts commit 60dcdaf.
…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. |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this 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!
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