-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
System.IO.Packaging.Open throws FileFormatException saying File contains corrupted data when the size of the package is more than 4GB and targeting .NET Framework #94899
Comments
Tagging subscribers to this area: @dotnet/area-system-io-compression Issue DetailsDescriptionOur DacFx code uses System.IO.Packaging for packing the schema and when it is packaged with more than 4GB, it throw FileFormat Exception saying File contains corrupted data when it is used in a console app targeting .NET Framework but the same package loads fine in .NET Core File contains corrupted data. Program Location: at MS.Internal.IO.Zip.ZipIOLocalFileBlock.Validate(String fileName, ZipIOCentralDirectoryBlock centralDir, ZipIOCentralDirectoryFileHeader centralDirFileHeader) Reproduction Steps
Expected behaviorIt should open the package in the console app targeting .Net Framework Actual behaviorIt throws File Format exception saying File contains corrupted data when it works fine in the console app targeting .NET core Regression?No response Known WorkaroundsOpen the package in the console app targeting .NET Core ConfigurationNo response Other informationIt has been reported here in dotnet/wpf#2676 and because of this issue, we have an issue opened in DacFx microsoft/DacFx#363
|
We can repro this with version 5.0.0 but it's possible the issue was in prior versions too |
Exception occurs due to the versionNeeded is different in the local header (20, Deflate) compared to that in central directory (45, ZIP64). The underlying reason is that all small files after large files (>4GB) requires ZIP64 header because their LH offsets are >4GB. It's unclear in the PKWare spec whether the discrepancy is allowed, but the latest .NET doesn't validate that as the Framework used to do. 7-Zip set both ZIP64 flags in LH and CD for file offsetting >4GB. If the discrepancy is allowed, the bug can only be fixed from the Framework side because the issue is within If it's not allowed, the current ZIP LH writing impl in .NET is wrong. I would propose a fix as in #94970. |
ZipArchiveEntry didn't set ZIP64 in local headers for small files if their offset are >4GB.
@karakasa, My understanding is that the central directory headers must match the local file headers. The central directory header is intended to provide a quick lookup of all zip file metadata without needing to scan the entire file. It should contain identical data to the local file header. Mismatched headers may indicate corruption and is invalid. As an example, multiple compression methods in the spec also specify the expectation that the compression method will match in both the central directory headers and local file headers. |
@karakasa I was wondering if this fixed in net8? |
@SeenaAugusty not yet but we will backport it to 8.0 once the fix is merged. |
@carlossanlop do you have any ETA on when this fix will be ported to 8.0? in which sdk version? |
We need to merge the fix to main first, then we can backport it and have it included in the upcoming release at that point. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
@carlossanlop any update on this bug? |
ZipArchiveEntry didn't set ZIP64 in local headers for small files if their offset are >4GB.
ZipArchiveEntry didn't set ZIP64 in local headers for small files if their offset are >4GB.
ZipArchiveEntry didn't set ZIP64 in local headers for small files if their offset are >4GB.
Description
Our DacFx code uses System.IO.Packaging for packing the schema and when it is packaged with more than 4GB, it throw FileFormat Exception saying File contains corrupted data when it is used in a console app targeting .NET Framework but the same package loads fine in .NET Core
File contains corrupted data.
Program Location:
Reproduction Steps
Expected behavior
It should open the package in the console app targeting .Net Framework
Actual behavior
It throws File Format exception saying File contains corrupted data when it works fine in the console app targeting .NET core
Regression?
No response
Known Workarounds
Open the package in the console app targeting .NET Core
Configuration
No response
Other information
It has been reported here in dotnet/wpf#2676 and because of this issue, we have an issue opened in DacFx microsoft/DacFx#363
The text was updated successfully, but these errors were encountered: