-
Notifications
You must be signed in to change notification settings - Fork 93
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
embed.rs: Added error check when ISO file incomplete #908
Conversation
c5e9f03
to
f820dab
Compare
Thanks for pursuing this! I don't think the karg embed area parser is the right place to put this check, because any other code that reads data from the ISO could encounter the same problem. Instead, let's do this validation when initially parsing the ISO. Jonathan's suggestion requires reading all of the ISO image's directories, and per the above we'd do it every time we parsed an ISO. Instead, I'd suggest comparing the Volume Space Size field in the Primary Volume Descriptor to the file size, which should save a bunch of I/O. That wouldn't detect the case where an invalid ISO image claims to have files beyond the Volume Space Size, but we're only trying to catch a truncated download, not arbitrary data corruption, so that should be okay. Note that the actual file size will likely be larger than the Volume Space Size, because CI is failing because you need to run |
Currently this is what the Primary Volume Descriptor returns |
The address is measured in sectors, not bytes. (Filesystem data structures often do this, since they point to things at sector boundaries. The lower bits of the address would be wasted otherwise.) coreos-installer has an existing parse function that creates the |
c71892b
to
8545aa4
Compare
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.
Overall structure looks good. 🎉 Some cleanups.
Also, let's update |
Oh, also, we've switched to updating |
ac5f48d
to
1eef3a8
Compare
docs/release-notes.md
Outdated
@@ -12,6 +12,7 @@ Major changes: | |||
Minor changes: | |||
|
|||
- Add release notes to documentation | |||
- Added an error check for detecting an incomplete ISO image |
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.
Maybe just something like
- Added an error check for detecting an incomplete ISO image | |
- iso: Detect incomplete ISO files |
?
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.
Maybe "iso: Improve error for incomplete ISO files"? We were detecting it before, just with an obscure message.
1eef3a8
to
ce52587
Compare
Added an "Incomplete download of ISO image" error check to the ISO9660 parser and a following test to verify it.
ce52587
to
4f060f5
Compare
Updated |
Ok(Self { descriptors, file }) | ||
let iso_fs = Self { descriptors, file }; | ||
let primary = iso_fs.get_primary_volume_descriptor()?; | ||
if primary.volume_space_size * ISO9660_SECTOR_SIZE as u64 > 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 think in the case of a corrupted ISO this multiplication could overflow? Probably worth something like:
if primary.volume_space_size * ISO9660_SECTOR_SIZE as u64 > length { | |
if primary.volume_space_size.checked_mul(ISO9660_SECTOR_SIZE as u64).ok_or_else(|| anyhow!("Invalid ISO volume size"))? > length |
or so?
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're only trying to catch a truncated download, not arbitrary data corruption
Yes you are correct but I assumed the above to be true
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.
volume_space_size
is 32 bits on disk, so this can't overflow.
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.
Looks great!
Follows on Issue#869 and Jira cos-1556
Giving clearer error message when ISO file is not complete
Implements jlebon's suggestion
last file's offset + file length <= ISO length
The new error message displayed when incomplete ISO file detected is:
Error: ISO Image is wrong and can't be modified