Skip to content

Conversation

@casperisfine
Copy link
Contributor

@casperisfine casperisfine commented Apr 10, 2025

For a reason unknown, even though pos is stored as a long, the #pos and #pos= treat it as an int, which prevent seeking into strings larger than 2GiB.

cc @kou

def test_large_string
six_gib = (6 * 1024 * 1024 * 1024)
string = "a" * six_gib
s = create_string_scanner(string) # 6 GiB string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that we need at least 6 GiB memory to run this test...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. I don't know how to test it otherwise. I could reduce the size to a bit more than 4GiB, or even 2GiB given it's signed.

We could also just not test it, but this revealed that the Java version has the same limitation, so I think it was valuable. (I won't update the JRuby version though, because there everything uses an int so it's way to much work for me. cc @headius)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up removing the test, as it also doesn't work on windows, nor on 32bit systems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

@casperisfine casperisfine force-pushed the long-pos branch 2 times, most recently from e54d2f7 to e6b8698 Compare April 11, 2025 07:45
@byroot byroot changed the title Allow parsing strings larger than 4GiB Allow parsing strings larger than 2GiB Apr 11, 2025
@casperisfine casperisfine force-pushed the long-pos branch 2 times, most recently from ad278f2 to 58505f7 Compare April 11, 2025 12:21
For a reason unknown, even though `pos` is stored as a `long`,
the `#pos` and `#pos=` treat it as an `int`, which prevent
skeeing into strings larger than 2GiB.
@kou kou merged commit b763684 into ruby:master Apr 13, 2025
38 checks passed
matzbot pushed a commit to ruby/ruby that referenced this pull request Apr 14, 2025
(ruby/strscan#147)

For a reason unknown, even though `pos` is stored as a `long`, the
`#pos` and `#pos=` treat it as an `int`, which prevent seeking into
strings larger than 2GiB.

ruby/strscan@b76368416e

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
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.

3 participants