Skip to content

Keep the given running value in Zlib.crc32(nil, crc) and Zlib.adler32(nil, adler) - #176

Open
segiddins wants to merge 1 commit into
ruby:masterfrom
segiddins:segiddins/checksum-nil-running-value
Open

segiddins wants to merge 1 commit into
ruby:masterfrom
segiddins:segiddins/checksum-nil-running-value

Conversation

@segiddins

Copy link
Copy Markdown
Contributor

For a nil string the checksum was computed as crc32(crc, NULL, 0), but zlib returns the initial value whenever the buffer is NULL, discarding the running value that was passed in.

Zlib.crc32(nil, 1234)
# expected: 1234 (as Zlib.crc32("", 1234))
# actual:   0
Zlib.adler32(nil, 1234)
# expected: 1234
# actual:   1

…(nil, adler)

For a nil string the checksum was computed as crc32(crc, NULL, 0), but zlib returns the initial value whenever the buffer is NULL, discarding the running value that was passed in.

```ruby
Zlib.crc32(nil, 1234)
# expected: 1234 (as Zlib.crc32("", 1234))
# actual:   0
Zlib.adler32(nil, 1234)
# expected: 1234
# actual:   1
```

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
@hsbt

hsbt commented Nov 26, 2026

Copy link
Copy Markdown
Member

This changes documented behavior: the rdoc of Zlib.crc32 and Zlib.adler32 says they return the initial value when string is omitted, which mirrors zlib's own rule for a Z_NULL buffer, and passing nil is how string is omitted. Did you run into a case where crc32(nil, crc) needed to return crc? That would help decide which behavior to keep.

This branch has not been deployed

No deployments
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 this pull request may close these issues.

2 participants