On Saturday, July 12, 2025 at 7:58:44 PM UTC+10 Kim Davies wrote:
heap-buffer-overflow in lutf8lib.c:220:14
The example (once unzipped and reformatted so that encoding doesn't break it) is:
utf8.offset("\x9c", -1, q)
The code at the end of `byteoffset` in lutf8lib appears to have an overflow for skipping to final byte:
```
/* ... from line 215 of lutf8lib.c at git master (currently 848568790826b7e201f84682185b5b605c473016) */
}
lua_pushinteger(L, posi + 1); /* initial position */
if ((s[posi] & 0x80) != 0) { /* multi-byte character? */
do {
posi++;
} while (iscontp(s + posi + 1)); /* skip to final byte */ // <-- HERE
}
/* else one-byte character: final position is the initial one */
lua_pushinteger(L, posi + 1); /* 'posi' now is the final position */
return 2;
```
For the single byte string, it appears to be a multibyte character, but the posi is incremented already, so the `iscontp` macro indexes `s[2]` which is past the null byte on the end.