mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
base: don't read past the end of the slice in parse_number_{u64,f64}
This commit is contained in:
1 parent
2a6876f8bb
commit
9d41525a2f
4 files changed
+61
-36
No files matched your search
@@ -1082,6 +1082,22 @@ test_wuffs_strconv_parse_number_f64_regular() {
|
||||
}
|
||||
}
|
||||
|
||||
// Input that ends right after a sign or an exponent marker must be rejected
|
||||
// without reading past the end of the slice. Use DEFAULT_OPTIONS, as
|
||||
// ALLOW_UNDERSCORES takes a different code path.
|
||||
{
|
||||
const char* strs[] = {"", "+", "-", "1e", "1E", "12.5e"};
|
||||
for (size_t i = 0; i < WUFFS_TESTLIB_ARRAY_SIZE(strs); i++) {
|
||||
wuffs_base__result_f64 r = wuffs_base__parse_number_f64(
|
||||
wuffs_base__make_slice_u8((uint8_t*)(void*)strs[i], strlen(strs[i])),
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);
|
||||
if (r.status.repr != wuffs_base__error__bad_argument) {
|
||||
RETURN_FAIL("\"%s\": have \"%s\", want \"%s\"", strs[i],
|
||||
r.status.repr, wuffs_base__error__bad_argument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1245,6 +1261,23 @@ test_wuffs_strconv_parse_number_u64() {
|
||||
}
|
||||
}
|
||||
|
||||
// A bare "0x" or "0d" prefix is invalid, even with
|
||||
// ALLOW_MULTIPLE_LEADING_ZEROES. Pass an explicit length (not strlen) so
|
||||
// that the byte just past the end of the slice is a digit, which must not be
|
||||
// read.
|
||||
{
|
||||
const char* strs[] = {"0x7", "0X7", "0d7", "0D7"};
|
||||
for (size_t i = 0; i < WUFFS_TESTLIB_ARRAY_SIZE(strs); i++) {
|
||||
wuffs_base__result_u64 r = wuffs_base__parse_number_u64(
|
||||
wuffs_base__make_slice_u8((uint8_t*)(void*)strs[i], 2),
|
||||
WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES);
|
||||
if (r.status.repr != wuffs_base__error__bad_argument) {
|
||||
RETURN_FAIL("\"%.2s\": have \"%s\", want \"%s\"", strs[i],
|
||||
r.status.repr, wuffs_base__error__bad_argument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES.
|
||||
{
|
||||
for (int o = 0; o < 2; o++) {
|
||||
|
||||
Reference in new issue
Block a user