Skip to content
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

Str.regexp raises "Invalid_argument: index out of bounds" #7369

Closed
vicuna opened this issue Sep 23, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Sep 23, 2016

Original bug ID: 7369
Reporter: @johnwhitington
Assigned to: @damiendoligez
Status: resolved (set by @xavierleroy on 2016-12-04T15:34:48Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 4.03.0
Target version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Fixed in version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Category: otherlibs
Monitored by: @gasche

Bug description

#load "str.cma";;

let x = "if\( \|\t\|\n\|\f\|\t\|\).\( \|\t\|\n\|\f\|\t\|\)=\( \|\t\|\n\|\f\|\t\|\).*";;

val x : string =
"if\( \|\t\|\n\|\f\|\t\|\).\( \|\t\|\n\|\f\|\t\|\)=\( \|\t\|\n\|\f\|\t\|\).*"

Str.regexp x;;

Exception: Invalid_argument "index out of bounds".

Additional information

The backtrace is not very useful, just pointing to recursive invocations of emit_code:

Raised by primitive operation at file "str.ml", line 254, characters 4-49
Called from file "str.ml", line 385, characters 6-17
Called from file "str.ml", line 344, characters 6-17
Called from file "str.ml", line 413, characters 6-17
Called from file "str.ml", line 422, characters 2-14

@vicuna

This comment has been minimized.

Copy link
Author

commented Sep 27, 2016

Comment author: @johnwhitington

I missed the top line. The error is in patch_instr at l254

(* Fill a reserved instruction slot with a GOTO or PUSHBACK instruction *)
let patch_instr pos opc dest =
(!prog).(pos) <- (instr opc (displ dest pos)) in

from a Group (n, r) call to emit_code at l385
from a Star r match at l344

Here are the input values to patch_instr for the whole run:

Str.regexp x;;

patch_instr prog length = 32, opc = 16, dest = 11, pos = 8
patch_instr prog length = 32, opc = 15, dest = 12, pos = 10
patch_instr prog length = 32, opc = 16, dest = 13, pos = 7
patch_instr prog length = 32, opc = 15, dest = 14, pos = 12
patch_instr prog length = 32, opc = 16, dest = 15, pos = 6
patch_instr prog length = 32, opc = 15, dest = 16, pos = 14
patch_instr prog length = 32, opc = 16, dest = 17, pos = 5
patch_instr prog length = 32, opc = 15, dest = 18, pos = 16
patch_instr prog length = 32, opc = 16, dest = 19, pos = 4
patch_instr prog length = 32, opc = 15, dest = 19, pos = 18
patch_instr prog length = 32, opc = 16, dest = 22, pos = 1
patch_instr prog length = 32, opc = 16, dest = 25, pos = 22
patch_instr prog length = 64, opc = 16, dest = 35, pos = 32
patch_instr prog length = 64, opc = 15, dest = 36, pos = 34
patch_instr prog length = 64, opc = 16, dest = 37, pos = 31
patch_instr prog length = 64, opc = 15, dest = 38, pos = 36
patch_instr prog length = 64, opc = 16, dest = 39, pos = 30
patch_instr prog length = 64, opc = 15, dest = 40, pos = 38
patch_instr prog length = 64, opc = 16, dest = 41, pos = 29
patch_instr prog length = 64, opc = 15, dest = 42, pos = 40
patch_instr prog length = 64, opc = 16, dest = 43, pos = 28
patch_instr prog length = 64, opc = 15, dest = 43, pos = 42
patch_instr prog length = 64, opc = 16, dest = 46, pos = 25
patch_instr prog length = 64, opc = 16, dest = 57, pos = 54
patch_instr prog length = 64, opc = 15, dest = 58, pos = 56
patch_instr prog length = 64, opc = 16, dest = 59, pos = 53
patch_instr prog length = 64, opc = 15, dest = 60, pos = 58
patch_instr prog length = 64, opc = 16, dest = 61, pos = 52
patch_instr prog length = 64, opc = 15, dest = 62, pos = 60
patch_instr prog length = 64, opc = 16, dest = 63, pos = 51
patch_instr prog length = 64, opc = 15, dest = 64, pos = 62
patch_instr prog length = 64, opc = 16, dest = 65, pos = 50
patch_instr prog length = 64, opc = 15, dest = 65, pos = 64

So it's trying to patch an instruction in the bytecode at position 64 in a bytecode program array 0...63.

@vicuna

This comment has been minimized.

Copy link
Author

commented Sep 27, 2016

Comment author: @damiendoligez

See #826 ( #826 ).

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 4, 2016

Comment author: @xavierleroy

GRP#826 merged, fixing this bug.

@vicuna vicuna closed this Dec 4, 2016

@vicuna vicuna added the otherlibs label Mar 14, 2019

@vicuna vicuna added this to the 4.05.0 milestone Mar 14, 2019

@vicuna vicuna added the bug label Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.