8000 Failure in `StringScanner#scan_integer` when running the HexaPDF test suite · Issue #8823 · jruby/jruby · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Failure in StringScanner#scan_integer when running the HexaPDF test suite #8823

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

Open
gettalong opened this issue May 2, 2025 · 2 comments · Fixed by ruby/strscan#150
Open

Comments

@gettalong
Copy link

I installed JRuby 10 to see if the test suite of HexaPDF runs successfully. Alas it crashes with an error.

Environment Information

  • JRuby version: jruby 10.0.0.0 (3.4.2) 2025-04-13 6ed59bc847 OpenJDK 64-Bit Server VM 21.0.6+7-Ubuntu-124.10.1 on 21.0.6+7-Ubuntu-124.10.1 +indy +jit [x86_64-linux]
  • Operating system and platform: Linux laptop 6.11.0-21-generic #21-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 19 16:50:40 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

To reproduce

  1. git clone git@github.com:gettalong/hexapdf.git
  2. gem install cmdparse geom2d openssl strscan
  3. rake test

Expected Behavior

The test suite should run successfully.

Actual Behavior

The test suite fails with the following stack trace:

ArgumentError: invalid value for Integer(): "xref\n0 8\n0000000000 65535 f \n0000000015 00000 n \n0000000064 00000 n \n0000000149 00000 n \n0000000229 00000 n \n0000000329 00000 n \n0000000396 00000 n \n0000000476 00000 n \ntrailer << /Root 1 0 R /Info 7 0 R /Size 8 /ID [<6790ffa610024e78369114311fc0df96><6790ffa610024e78369114311fc0df96>] >>\nstartxref\n523\n%%EOF\n"
             scan_base10_integer at org/jruby/ext/strscan/RubyStringScanner.java:602
                    scan_integer at /home/thomas/.rbenv/versions/jruby-10.0.0.0/lib/ruby/gems/shared/gems/strscan-3.1.4-java/lib/strscan/strscan.rb:18
                    parse_number at /home/thomas/exthdsync/personal/repos/hexapdf/lib/hexapdf/tokenizer.rb:290
                      next_token at /home/thomas/exthdsync/personal/repos/hexapdf/lib/hexapdf/tokenizer.rb:124
  parse_xref_section_and_trailer at /home/thomas/exthdsync/personal/repos/hexapdf/lib/hexapdf/parser.rb:287
                   load_revision at /home/thomas/exthdsync/personal/repos/hexapdf/lib/hexapdf/parser.rb:243
                         from_io at /home/thomas/exthdsync/personal/repos/hexapdf/lib/hexapdf/revisions.rb:81
                      initialize at /home/thomas/exthdsync/personal/repos/hexapdf/lib/hexapdf/document.rb:195
                             new at org/jruby/RubyClass.java:1023
                          <main> at /home/thomas/exthdsync/personal/repos/hexapdf/test/hexapdf/encryption/test_standard_security_handler.r
b:70
                     module_eval at org/jruby/RubyModule.java:4173
                     module_eval at org/jruby/RubyModule.java:4204
                        describe at /home/thomas/.rbenv/versions/jruby-10.0.0.0/lib/ruby/gems/shared/gems/minitest-5.25.4/lib/minitest/spe
c.rb:95
                          <main> at /home/thomas/exthdsync/personal/repos/hexapdf/test/hexapdf/encryption/test_standard_security_handler.r
b:65
                         require at org/jruby/RubyKernel.java:1183
                         require at /home/thomas/.rbenv/versions/jruby-10.0.0.0/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:136
                          <main> at /home/thomas/.rbenv/versions/jruby-10.0.0.0/lib/ruby/gems/shared/gems/rake-13.2.1/lib/rake/rake_test_l
oader.rb:21
                          select at org/jruby/RubyArray.java:2954
                          <main> at /home/thomas/.rbenv/versions/jruby-10.0.0.0/lib/ruby/gems/shared/gems/rake-13.2.1/lib/rake/rake_test_l
oader.rb:6
rake aborted!
Command failed with status (1)
org/jruby/ext/monitor/Monitor.java:85:in 'synchronize'
org/jruby/ext/monitor/Monitor.java:85:in 'synchronize'
Tasks: TOP => default => test
(See full trace by running task with --trace)
@headius
Copy link
Member
headius commented May 3, 2025

Oy vey... pretty face-palmy bug.

diff --git a/ext/jruby/org/jruby/ext/strscan/RubyStringScanner.java b/ext/jruby/org/jruby/ext/strscan/RubyStringScanner.java
index c0b654d..6e6501f 100644
--- a/ext/jruby/org/jruby/ext/strscan/RubyStringScanner.java
+++ b/ext/jruby/org/jruby/ext/strscan/RubyStringScanner.java
@@ -651,7 +651,7 @@ public class RubyStringScanner extends RubyObject {
         setMatched();
         adjustRegisters();
 
-        return ConvertBytes.byteListToInum(runtime, bytes, ptr, len, base, true);
+        return ConvertBytes.byteListToInum(runtime, bytes, ptr, ptr + len, base, true);
     }
 
     private void strscanMustAsciiCompat(Ruby runtime) {

The parameter here is supposed to the end index, not the total length. With this the test suite runs and everything seems to pass except the digital signing stuff. I'll get this fix into the next release of strscan.

@headius
Copy link
Member
headius commented May 3, 2025

Trivial reproduction:

require 'strscan'
ss = StringScanner.new("asdf\n1")
ss.pos = 5
puts ss.scan_integer

There must not be tests of scanning for numbers at a non-zero offset.

headius added a commit to ruby/strscan that referenced this issue May 3, 2025
headius added a commit to ruby/strscan that referenced this issue May 3, 2025
@headius headius added this to the JRuby 9.4.13.0 milestone May 3, 2025
kou pushed a commit to ruby/strscan that referenced this issue May 3, 2025
These parse methods take begin and end indices, not begin and length. A
test is included.

Fixes jruby/jruby#8823
matzbot pushed a commit to ruby/ruby that referenced this issue May 8, 2025
(ruby/strscan#150)

These parse methods take begin and end indices, not begin and length. A
test is included.

Fixes jruby/jruby#8823

ruby/strscan@9690e39e73
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.

2 participants
0