Skip to content

Conversation

bnoordhuis
Copy link
Contributor

Not all functions access the string's backing memory according to the string's encoding. js_regexp_match in particular uses str8 for both ascii and wide strings. Because the offset into the parent string was stored in characters, js_regexp_match used the wrong offset (off by 50%) for wide slice strings.

It's conceivable other functions do something similarly ill-advised, so store the start in bytes instead of characters from now on.

Fixes: #1178

Not all functions access the string's backing memory according to the
string's encoding. js_regexp_match in particular uses str8 for both
ascii and wide strings. Because the offset into the parent string
was stored in characters, js_regexp_match used the wrong offset (off
by 50%) for wide slice strings.

It's conceivable other functions do something similarly ill-advised,
so store the start in bytes instead of characters from now on.

Fixes: quickjs-ng#1178
@saghul
Copy link
Contributor

saghul commented Oct 11, 2025

Nice one!

@bnoordhuis bnoordhuis merged commit 73be8a5 into quickjs-ng:master Oct 11, 2025
127 checks passed
@bnoordhuis bnoordhuis deleted the fix1178 branch October 11, 2025 12:33
@anuraaga
Copy link

Thanks @bnoordhuis! Confirmed this commit fixes the issue for me as well. Just curious, is it possible to add a regression test for it? If a JS one is too difficult maybe a C one is still reasonable.

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

Successfully merging this pull request may close these issues.

cannot read property of null with no stacktrace on latest head

3 participants