Skip to content

gsub lookahead cannot allocate memory #2354

@stoat1

Description

@stoat1

Describe the bug
When using regex lookahead jq freezes, eats up all system memory, prints an error message and eventually aborts

To Reproduce

$ jq -n '"qux" | gsub("(?<=u)"; "u")'
"quux"

$ free -g
              total        used        free      shared  buff/cache   available
Mem:             15           5           6           0           3           8
Swap:             1           0           1

$ jq -n '"qux" | gsub("(?=u)"; "u")'
error: cannot allocate memory
[1]    123456 abort (core dumped)  jq -n '"qux" | gsub("(?=u)";  #"u")'

Expected behavior
jq outputs the result and exit

Environment

  • Ubuntu 20.04.2 LTS
  • jq-1.6

Additional context
I'm aware that this may be an issue in Oniguruma but I wasn't able to reproduce it due to my lack of experience with C

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions