[PR #301] [MERGED] Zlib: fix Adler32 implementation #956

Closed
opened 2026-01-29 22:18:21 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/301
Author: @frabar666
Created: 9/17/2017
Status: Merged
Merged: 9/17/2017
Merged by: @adamhathcock

Base: masterHead: fix-adler32


📝 Commits (2)

  • 3e29edd Zlib: fix Adler32 implementation
  • 75de73d Merge branch 'master' into fix-adler32

📊 Changes

1 file changed (+4 additions, -4 deletions)

View changed files

📝 src/SharpCompress/Compressors/Deflate/Zlib.cs (+4 -4)

📄 Description

ZlibStream's Adler32 routine sometime returns incorrect results, as @ied206 noticed in #298.
This fixes #298 by using uint instead of int.

There are no unit tests, because the implementation is internal.
PHP's short test cases are OK, but they were already OK before.

My gut says the issue was due to the % operator not behaving as expected for negative ints, so I tested a 5000-byte 0xFF sequence (to approach the overflow limit at 5552). It exhibits the same pattern as #298, 1st and 5th-8th digits match, but 2nd-4th digits are different: previous implementation returned 0x53e07596, new one returns 0x54b27596 (same as an online Adler32 calculator).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/301 **Author:** [@frabar666](https://github.com/frabar666) **Created:** 9/17/2017 **Status:** ✅ Merged **Merged:** 9/17/2017 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `master` ← **Head:** `fix-adler32` --- ### 📝 Commits (2) - [`3e29edd`](https://github.com/adamhathcock/sharpcompress/commit/3e29edd487717ee426befd822fdc3d1e9cec9bf5) Zlib: fix Adler32 implementation - [`75de73d`](https://github.com/adamhathcock/sharpcompress/commit/75de73d20d55c25f45129cf73383454d4fc0ac67) Merge branch 'master' into fix-adler32 ### 📊 Changes **1 file changed** (+4 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Compressors/Deflate/Zlib.cs` (+4 -4) </details> ### 📄 Description `ZlibStream`'s `Adler32` routine sometime returns incorrect results, as @ied206 noticed in #298. This fixes #298 by using `uint` instead of `int`. There are no unit tests, because the implementation is internal. [PHP's short test cases](https://github.com/php/php-src/blob/master/ext/hash/tests/adler32.phpt) are OK, but they were already OK before. My gut says the issue was due to the `%` operator not behaving as expected for negative `int`s, so I tested a 5000-byte 0xFF sequence (to approach the overflow limit at 5552). It exhibits the same pattern as #298, 1st and 5th-8th digits match, but 2nd-4th digits are different: previous implementation returned `0x53e07596`, new one returns `0x54b27596` (same as an online Adler32 calculator). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:18:21 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#956