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

Corrupted data when the compression method 0x08 -> 0x00 / compressed size info [02 00 00 00] #3

Closed
3F opened this issue Aug 15, 2017 · 1 comment

Comments

@3F
Copy link
Owner

3F commented Aug 15, 2017

Possible bug with packages was described here:
3F/DllExport#38 (comment)

  • Compression method: Deflate (0x08) -> Uncompressed (0x00)
  • Actual uncompressed size == 0
  • Compressed size == 2

GetNuTool processes packages through System.IO.Packaging.ZipPackage and for this data we can't use this at all:

source.CopyTo(Stream destination);
source.Read(byte[] buffer, int offset, int count);
(new StreamReader(source)).Read(char[] buffer, int index, int count)
(new StreamReader(source)).ReadToEnd();
...

all above will throw exception because of corrupted data and/or incorrect internal processing.

btw:

 // source.Length == 2 
 source.Seek(0, SeekOrigin.Begin);
 source.ReadByte(); // 0x03
 source.ReadByte(); // Exception

 source.Seek(-1, SeekOrigin.End);
 source.ReadByte(); // 0x00
 source.ReadByte(); // -1  end of the stream

 source.Seek(-2, SeekOrigin.End);
 source.ReadByte(); // 0x03
 source.ReadByte(); // Exception

Through ZipPackage implementation we also have no any information about position from file outside processed part. Or does it available ? o_O

Because for this case we can process this manually:

Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00006850  55 9A DB D3 4F B0  FE 0F 50 4B  03 04 14 00  02 00    UљЫУO°ю.PK......
00006860 [00 00]21 B2 0C 4B [00 00 00 00][02 00 00 00] 00 00    ..!І.K..........
00006870  00 00 0E 00 1C 00  74 6F 6F 6C  73 2F 69 6E  69 74    ......tools/init
00006880  2E 70 73 31 20 A2  18 00 28 A0  14 00 00 00  00 00    .ps1 ў..( ......
00006890  00 00 00 00 00 00  00 00 00 00  00 00 00 00  00 00    ................

other header:

Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00003F80  79 F0  E4 37 50 4B  03 04 14 00  02 00 [00 00] 21 B2  yрд7PK........!І
00003F90  0C 4B [00 00 00 00][02 00 00 00] 00 00 00 00 0D 00  .K..............
00003FA0  1C 00  6C 69 62 2F  6E 65 74 32  30 2F 5F 2E 5F 20  ..lib/net20/_._ 
00003FB0  A2 18  00 28 A0 14  00 00 00 00  00 00 00 00 00 00  ў..( ...........

incorrect_package_data

that is, from headers above we have information about uncompressed type data, with compressed size == 2, and actual 0 bytes.

specific exception because of incorrect crc:

  • MS.Internal.IO.Zip.ProgressiveCrcCalculatingStream.Read(Byte[] buffer, Int32 offset, Int32 count)
...
if (this._validateCrcWithExpectedCrc && this.CanValidateCrcWithoutRead() && this.CrcCalculator.Crc != this._expectedCrc)
{
	throw new FileFormatException(SR.Get("CorruptedData"));
}

well, seems try/catch is the most easy way to process this case, because it's bug of the System.IO.Packaging.ZipPackage and from nuget.org. Details here: 3F/DllExport#38

Any suggestions are welcome.

@3F
Copy link
Owner Author

3F commented Aug 17, 2017

how it should be now:

gnt /p:ngpackages="DllExport/1.6-beta" /p:debug=true
Getting `DllExport/1.6-beta` ... Extracting into "D:\prg\projects\DllExport\exp_gnt\GetNuTool\versions\01. executable\packages\DllExport.1.6-beta"
- `/3rd-party.txt`
- `/build/net20/DllExport.targets`
- `/build_info.txt`
- `/changelog.txt`
- `/DllExport.bat`
- `/DllExport.nuspec`
- `/lib/net20/_._`
[x]?crc: D:\prg\projects\DllExport\exp_gnt\GetNuTool\versions\01. executable\packages\DllExport.1.6-beta\lib/net20/_._
- `/License.txt`
- `/Readme.md`
- `/tools/build.targets`
- `/tools/coreclr/changelog.txt`
- `/tools/coreclr/coreclr.dll`
- `/tools/coreclr/ilasm.exe`
- `/tools/coreclr/ildasm.exe`
- `/tools/coreclr/ildasmrc.dll`
- `/tools/coreclr/LICENSE.TXT`
- `/tools/coreclr/mscordaccore.dll`
- `/tools/coreclr/mscordbi.dll`
- `/tools/coreclr/PATENTS.TXT`
- `/tools/coreclr/README.md`
- `/tools/coreclr/_Version.txt`
- `/tools/gnt.bat`
- `/tools/hMSBuild.bat`
- `/tools/init.ps1`
[x]?crc: D:\prg\projects\DllExport\exp_gnt\GetNuTool\versions\01. executable\packages\DllExport.1.6-beta\tools/init.ps1
- `/tools/Microsoft.Build.dll`
- `/tools/Microsoft.Build.Framework.dll`
- `/tools/Microsoft.Build.Utilities.v4.0.dll`
- `/tools/Microsoft.Management.Infrastructure.dll`
- `/tools/Mono.Cecil.dll`
- `/tools/MvsSln.dll`
- `/tools/MvsSln.pdb`
- `/tools/MvsSln.xml`
- `/tools/net.r_eg.DllExport.Configurator.dll`
- `/tools/net.r_eg.DllExport.Configurator.pdb`
- `/tools/net.r_eg.DllExport.targets`
- `/tools/net.r_eg.DllExport.Wizard.dll`
- `/tools/net.r_eg.DllExport.Wizard.pdb`
- `/tools/net.r_eg.DllExport.Wizard.targets`
- `/tools/NSBin.dll`
- `/tools/NSBin.pdb`
- `/tools/raw/lib/net20/DllExport.dll`
- `/tools/RGiesecke.DllExport.dll`
- `/tools/RGiesecke.DllExport.MSBuild.dll`
- `/tools/RGiesecke.DllExport.MSBuild.pdb`
- `/tools/RGiesecke.DllExport.pdb`
- `/tools/System.Management.Automation.dll`

3F added a commit that referenced this issue Aug 18, 2017
* FIXED: Fixed problem "Input string was not in a correct format" when used version with release type,
         e.g.: 1.2.3-alpha, 1.2.3-beta-2, 1.2.3-rc ...

* FIXED: Avoids errors with possible incorrect CRC & Compressed size info. Issue #3
* FIXED: Fixed problems with paths and whitespace characters for `-unpack` command in executable version.
* CHANGED: Removed '15.0' from searching by registry key as an unused way for all new VS2017+
* CHANGED: 'MSBuild was not found' now returns (0x2) ERROR_FILE_NOT_FOUND
* CHANGED: Сhanged variable name %msbuild% to %msbuildexe% that was related for Issue #2
* CHANGED: Improved comparing arguments for executable version.
@3F 3F closed this as completed Aug 18, 2017
3F added a commit to 3F/DllExport that referenced this issue Aug 19, 2017
…problems with possible incorrect CRC & Compressed size info - #38

3F/GetNuTool#3
#38 (comment)
3F added a commit to 3F/DllExport that referenced this issue Aug 19, 2017
* NOTE: This release contains trivial fixes only for our manager because of problems with nuget.org. Issue #38.
        Please read all changes in previous beta release and please note again - you shouldn't use standard nuget clients anymore:
        https://www.youtube.com/watch?v=okPThdWDZMM

        Test and comment anything about this in Issue #38 if you need.

* FIXED: Updated GetNuTool v1.6.1 to fix problems with possible incorrect CRC & Compressed size info from nuget.org.

         Changelog here:
         https://github.com/3F/GetNuTool/blob/master/changelog.txt

         Related issues:
         * 3F/GetNuTool#3
         * #38 (comment)

* CHANGED: Changed url to get latest manager directly. Please use this if you need:
           * https://3F.github.io/DllExport/releases/latest/manager/

           Other versions you can find from GitHub Releases:
           * https://github.com/3F/DllExport/releases

           Or get it from nuget packages starting with v1.6+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant