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

(r)index("") do memory exhausted #1923

Closed
vodzous opened this issue Jun 9, 2019 · 6 comments
Closed

(r)index("") do memory exhausted #1923

vodzous opened this issue Jun 9, 2019 · 6 comments

Comments

@vodzous
Copy link

vodzous commented Jun 9, 2019

When testing my project 'yacc and jq in bash (ftp://ftp.simtreas.ru/pub/my/yacc_bash_jq.tgz)' I found a error in the jq version 1.6:
index("") and rindex("") do memory exhausted.

@pkoppstein
Copy link
Contributor

pkoppstein commented Jun 9, 2019

Running jq -n '"abc" | index("")' yields null using jq 1.5 or 1.6 (Mac OSX), so it is difficult to know what the problem is, given that there is no JSON or .jq file in the Yacc_bash_jq tarball.

(jq 1.4 did have a problem with index("").)

For the curious:

$ tar ztvf yacc_bash_jq.tgz
drwxr-xr-x  0 dzo    users       0 Jun  9 04:11 yacc_bash_jq/
-rw-r--r--  0 dzo    users     232 Jun  2 04:06 yacc_bash_jq/Makefile
-rw-r--r--  0 dzo    users   33697 Jun  9 03:48 yacc_bash_jq/jq.yb
-rw-r--r--  0 dzo    users   57757 Jun  9 04:11 yacc_bash_jq/yacc_bash.c

@vodzous
Copy link
Author

vodzous commented Jun 9, 2019

yields null using jq 1.5 or 1.6 jq -n '"abc" | index("")'
I get jq from download https://stedolan.github.io/jq/. All files have the date: Nov 2 2018
$ jq --version
jq-1.6
$ jq -n '"abc" | index("")'
make memory bomb

I think, index("") should eq 'lenght', not null :)

For the curious:
Excuse me, i do not understand.

@pkoppstein
Copy link
Contributor

@vodzous - Which OS?

@vodzous
Copy link
Author

vodzous commented Jun 9, 2019

Which OS?

Linux x86_64 3.10.17 SMP

@vodzous
Copy link
Author

vodzous commented Jun 9, 2019

I debugged jq and found infinite loop:
src/jv.c: jv_string_indexes():
while ((p = _jq_memmem(p, (jstr + jlen) - p, idxstr, idxlen)) != NULL) {
fprintf(stderr, "jv_string_indexes: idxlen=%d\n", idxlen);

#2 0x0000000000412ead in memory_exhausted () at src/jv_alloc.c:41
#3 0x0000000000412eda in jv_mem_alloc (sz=4903796368) at src/jv_alloc.c:124
#4 0x000000000040dc91 in jvp_array_alloc (size=306487272) at src/jv.c:186
#5 0x000000000040e124 in jvp_array_write (a=0x7fffffffd7f0, i=204324847) at src/jv.c:246
#6 0x000000000040e8c0 in jv_array_set (j=..., idx=204324847, val=...) at src/jv.c:356
#7 0x000000000040e96b in jv_array_append (j=..., val=...) at src/jv.c:364
#8 0x000000000040fbaf in jv_string_indexes (j=..., k=...) at src/jv.c:663
#9 0x000000000042d62a in f_string_indexes (jq=0x6572e0, a=..., b=...) at src/builtin.c:1126
#10 0x000000000040966f in jq_next (jq=0x6572e0) at src/execute.c:853
#11 0x000000000040374d in process (jq=0x6572e0, value=..., flags=0, dumpopts=645) at src/main.c:168
#12 0x0000000000405b77 in main (argc=3, argv=0x7fffffffe168) at src/main.c:631

@vodzous
Copy link
Author

vodzous commented Jun 10, 2019

Ah, this corrected in Feb 10 jv.c revision, not in 1.6 version.

@vodzous vodzous closed this as completed Jun 12, 2019
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

No branches or pull requests

2 participants