Skip to content
Myr

Tighten string length bounds and propagate invalid jv in implode

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

The bound added in CVE-2026-32316 (e47e56d22) still allowed `sizeof(jvp_string) + (currlen + len) * 2 + 1` to wrap `size_t` on 32-bit platforms. Tighten the threshold so the final allocation fits in 32-bit `size_t`. Also break out of `jv_string_implode` and `f_string_implode` once `jv_string_append_codepoint` returns an invalid `jv`; otherwise the next iteration triggers the assertion in `jvp_string_ptr` (or invokes undefined behavior under `-DNDEBUG`). Fixes CVE-2026-54679.

authored by itchyny · committed by itchyny · parent e987df0 · Browse files · 2 files+4 added−2 removed
This commit

State

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

Trailers

  • Co-authored-by: Dirk Müller <dirk@dmllr.de>

Diff stats

2 files+4 added−2 removed

  • other:+4 added−2 removed

2 files+4 added−2 removed

modified:src/builtin.c+1 added
1432 unmodified lines
1433 // outside codepoint range or in utf16 surrogate pair range1434 if (nv < 0 || nv > 0x10FFFF || (nv >= 0xD800 && nv <= 0xDFFF))1435 nv = 0xFFFD; // U+FFFD REPLACEMENT CHARACTER1436 s = jv_string_append_codepoint(s, nv);1437 if (!jv_is_valid(s)) break;1438 }14391440 jv_free(a);1441 return s;
710 unmodified lines
modified:src/jv.c+3 added-2 removed
1176 unmodified lines
11771178static jv jvp_string_append(jv string, const char* data, uint32_t len) {1179 jvp_string* s = jvp_string_ptr(string);1180 uint32_t currlen = jvp_string_length(s);1181 if ((uint64_t)currlen + len >= INT_MAX) {1181 if ((uint64_t)currlen + len >= INT_MAX - sizeof(jvp_string) / 2) {1182 jv_free(string);1183 return jv_invalid_with_msg(jv_string("String too long"));1184 }1185
192 unmodified lines
1378 return jv_null();1379 }1380 int len = jv_string_length_bytes(jv_copy(j));1381 int64_t res_len = (int64_t)len * n;1382 if (res_len >= INT_MAX) {1382 if ((uint64_t)res_len >= INT_MAX - sizeof(jvp_string) / 2) {1383 jv_free(j);1384 return jv_invalid_with_msg(jv_string("Repeat string result too long"));1385 }1386 if (res_len == 0) {
76 unmodified lines
1463 // outside codepoint range or in utf16 surrogate pair range1464 if (nv < 0 || nv > 0x10FFFF || (nv >= 0xD800 && nv <= 0xDFFF))1465 nv = 0xFFFD; // U+FFFD REPLACEMENT CHARACTER1466 s = jv_string_append_codepoint(s, nv);1467 if (!jv_is_valid(s)) break;1468 }14691470 jv_free(j);1471 return s;
714 unmodified lines