Skip to content
Myr

Array slice overflows (fix #1108)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nicolas Williams · committed by Nicolas Williams · parent 2fcb257 · Browse files · 2 files+21 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+21 added−4 removed

  • tests:+9 added−0 removed
  • other:+12 added−4 removed

2 files+21 added−4 removed

modified:src/jv.c+12 added-4 removed
294 unmodified lines
295 if (start == end) {296 jv_free(a);297 return jv_array();298 }299300 if (a.offset + start > 1 << (sizeof(a.offset) * CHAR_BIT)) {301 jv r = jv_array_sized(end - start);302 for (int i = start; i < end; i++)303 r = jv_array_append(r, jv_array_get(jv_copy(a), i));304 jv_free(a);305 return r;299 // FIXME FIXME FIXME large offsets300 a.offset += start;301 a.size = end - start;302 return a;306 } else {307 a.offset += start;308 a.size = end - start;309 return a;310 }311}312313/*314 * Arrays (public interface)
1038 unmodified lines
modified:tests/jq.test+9 added
381 unmodified lines
382[0,1,4,5,6,7]383[0,1,"a","b",4,5,6,7]384[0,1,"a","b","c",4,5,6,7]385386# Slices at large offsets (issue #1108)387#388# This is written this way because [range(<large number>)] is389# significantly slower under valgrind than .[<large number>] = value.390#391# We range down rather than up so that we have just one realloc.392reduce range(70010;69999;-1) as $i ([]; .[$i] = $i)|.[69999:70003]393null394[null,70000,70001,70002]395396#397# Variables398#
987 unmodified lines