Skip to content

Commit

Permalink
Fixed open byte overread in decodeURI() and decodeURIComponent().
Browse files Browse the repository at this point in the history
Found by OSS-Fuzz and MemorySanitizer.
  • Loading branch information
xeioex committed Jun 10, 2024
1 parent 00e996b commit e9f8cdf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/njs_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -4074,7 +4074,7 @@ njs_string_decode_uri(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
n++;
} while (((cp << n) & 0x80));

if (njs_slow_path(n > 4)) {
if (njs_slow_path(n > 4 || src + njs_length("%00") * (n - 1) > end)) {
goto uri_error;
}

Expand Down
4 changes: 4 additions & 0 deletions src/test/njs_unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -10016,13 +10016,17 @@ static njs_unit_test_t njs_test[] =
" '%',"
" '%0',"
" '%QQ',"
" '%C0%' + '0',"
" '%C0%10',"
" '%C0%80',"
" '%DC%C7',"
" '%80%81%82',"
" '%EF%5C%A0',"
" '%EF%A0%5E',"
" '%E0%EF%' + '0',"
" '%E0%EF%A0',"
" '%E0%A0%EF',"
" '%F0%A2%95%' + '0',"
" '%FF%A2%95%BB',"
"].every(v=>{try { decodeURI(v)} catch(e) {return e.name == 'URIError'}})"),
njs_str("true")},
Expand Down

0 comments on commit e9f8cdf

Please sign in to comment.