Skip to content

Use rb_len_t for string lengths - #150

Open
hsbt wants to merge 4 commits into
masterfrom
claude/clever-fermat-acc6bf
Open

hsbt wants to merge 4 commits into
masterfrom
claude/clever-fermat-acc6bf

Conversation

@hsbt

@hsbt hsbt commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Ruby master added rb_len_t for String and Array lengths (Feature #22400). It is long on every platform today, and long is 32 bits on x64-mswin64, so the lengths this extension keeps in long would truncate strings of 2GiB or more once rb_len_t widens there.

This switches the String lengths and offsets in ext/zlib/zlib.c to rb_len_t, with NUM2LEN and %"PRIdLEN" where they come from Ruby or go into an error message. MAX_UINT and checksum_long now decide whether to split a length for zlib's uInt by SIZEOF_RB_LEN_T instead of SIZEOF_LONG. Zlib::ZStream#avail_in also returns the pending input length with LEN2NUM instead of casting it to int, which turned a length over INT_MAX into a wrong or negative number.

Ruby without HAVE_RB_LEN_T gets a fallback that keeps long, so nothing changes on any platform for now.

Generated with Claude Code

hsbt and others added 4 commits October 10, 2026 03:58
These hold String lengths or offsets into them, so they would truncate on mswin once rb_len_t widens. The fallback keeps older Ruby building.

https://bugs.ruby-lang.org/issues/22400

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A constant cannot exceed long, so these casts need no rb_len_t.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MAX_UINT and checksum_long compared SIZEOF_LONG, so on mswin they would cast a length to uInt instead of clamping it once rb_len_t widens. The unsigned lengths taken by zstream_expand_buffer_into and zstream_buffer_ungets become rb_ulen_t so that they reach the clamp unnarrowed. Nothing changes while rb_len_t is long.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The int cast turned a remainder longer than INT_MAX into a wrong or negative number.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

1 participant