-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[release/9.0] [Tar] Fill in the file size even if the file is empty. #107633
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
Conversation
…tandard behavior.
Co-authored-by: Carlos Sánchez López <[email protected]>
|
Tagging subscribers to this area: @dotnet/area-system-formats-tar |
src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.Tests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.Tests.cs
Outdated
Show resolved
Hide resolved
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 support the scenario. We try to be as compatible as possible with file formats - both in what we produce and consume.
Can you let me know if we previously supported opening the bad archives we produced with these empty entries before this change? If we did, can we make sure to add a test to confirm that it continues to work?
If we didn't support reading them before, no need to add the test.
… is correct. Add test to verify that entries created with the malformed size field are still readable after the bug fix.
@ericstj - I tested the behavior that we had before the bug fix when reading entries that had a malformed size field value. I can confirm we were able to read those entries. I modified the existing test to not only confirm that the bytes in the size field have the new expected value, but that we can also read such entry with a proper TarReader. I also added a new test that creates an entry, then overwrites the size field value with the old malformed data (pure zeros), then opened the stream with a TarReader, and confirmed that we are still able to read such malformed entries without problem. |
ericstj
left a comment
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.
Thank you for adding the tests.
|
@artl93 can you review this one for RC2? |
|
You guys are fast. I was on PTO. |
The basic header fields are all exactly the same independently of the format, and size is one of those fields that remains unchanged regardless of the format. But you're welcome to add more tests with roundtrips for all formats. I kept my unit tests focused to only V7 as it's the simplest format. |
Backport of #106409 to release/9.0
/cc @carlossanlop @sobczyk @am11
Customer Impact
Reported in #95354
When TarWriter writes a regular file entry that has a size field zero, the entry ends up badly formatted.
The fix consists in making sure that when we write an entry, we write a value in the size metadata field not only when the data stream has a size greater than zero, but also when the size is zero and the data stream is not null. In any other case, we keep not writing anything to that field (like when there's no data stream).
Regression
It's been a bug from the beginning.
Testing
A TarWriter unit test was added to write a regular file entry that met this condition and checks the actual header bytes to confirm they look as expected.
Risk
Low. It's a targeted change for handling a very specific and uncommon case of regular file entry with a zero length data.