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

CRC Calculations Are Ocassionally Incorrect #229

Closed
barnstar opened this issue Jul 28, 2021 · 7 comments · Fixed by #243
Closed

CRC Calculations Are Ocassionally Incorrect #229

barnstar opened this issue Jul 28, 2021 · 7 comments · Fixed by #243

Comments

@barnstar
Copy link

The CRC calculation in the Data.process(...) is incorrect. In the case where the loop continues without stream.src_size getting set to zero, another pass with the same datablock is done on the CRC, causing it to be incorrect. compression_stream_process does not necessarily consume all the bytes.

unzip utilities on macOS are forgiving on incorrect CRCs (and ZIPFoundation itself lets you ignore them), but many other libraries will error out if the stored CRCs in the ZIP file don't match the CRC of the decoded file/bytes.

The correct action for COMPRESSION_STREAM_ENCODE is to run the CRC pass only when a new block of data is read from the provider.

@weichsel
Copy link
Owner

Thanks for making me aware of this.

Do you have a file at hand that showcases this behavior?

@andrewchang-bird
Copy link

I can repro this consistently when using ZIPFoundation to archive build products:

% unzip Mockingbird.zip
Archive:  Mockingbird.zip
  inflating: Mockingbird/LICENSE.md  
   creating: Mockingbird/Libraries/
  inflating: Mockingbird/Libraries/lib_InternalSwiftSyntaxParser.dylib  
  inflating: Mockingbird/Libraries/LICENSE.txt  
  inflating: Mockingbird/mockingbird   bad CRC 0e8ab0ad  (should be c9189cde)

Attached the file here: Mockingbird.zip

And here’s how we’re calling ZIPFoundation in our build pipeline: https://github.com/birdrides/mockingbird/blob/master/Sources/MockingbirdAutomationCli/Commands/Build.swift#L52-L55

You can repro it locally by checking out Mockingbird and running $ Sources/MockingbirdAutomationCli/buildAndRun.sh build cli --archive Mockingbird.zip

andrewchang-bird added a commit to typealiased/mockingbird that referenced this issue Jan 8, 2022
The new automation pipeline uses ZIP Foundation to create archives of
the build products. Unfortunately, ZIP Foundation produces malformed
CRCs for the mockingbird binary executable (see
weichsel/ZIPFoundation#229). This change replaces ZIP Foundation with
the Unix zip command and fixes how the Mockingbird.zip archive is
inflated by the CLI launcher.
@weichsel
Copy link
Owner

weichsel commented Jan 8, 2022

Opened a PR here: #243

@andrewchang-bird Does this fix your issue?

@andrewchang-bird
Copy link

Yep, looks like bugfix/invalidCRC32 fixes it.

@weichsel
Copy link
Owner

weichsel commented Jan 9, 2022

@andrewchang-bird Thanks for confirming. Merged - will be part of next release.

andrewchang-bird added a commit to typealiased/mockingbird that referenced this issue Jan 10, 2022
The new automation pipeline uses ZIP Foundation to create archives of
the build products. Unfortunately, ZIP Foundation produces malformed
CRCs for the mockingbird binary executable (see
weichsel/ZIPFoundation#229). This change replaces ZIP Foundation with
the Unix zip command and fixes how the Mockingbird.zip archive is
inflated by the CLI launcher.
@marcussc
Copy link

@weichsel thanks for this nice project and helping to get this issue fixed. Do you have an estimation when the next version with the fix will go live?

@weichsel
Copy link
Owner

Hi @marcussc
No ETA yet. Currently looking into another issue that still needs some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants