base: let parse_number_xxx return "arg too long"

Updates PR #184
This commit is contained in:
Nigel Tao committed 2026-10-21 12:04:44 +11:00
1 parent 7f70dda95c
commit d54d330601
5 files changed
+45

No files matched your search

@@ -1481,6 +1481,12 @@ wuffs_base__parse_number_f64(wuffs_base__slice_u8 s, uint32_t options) {
// As the pointer p walks the contents, it's faster to repeatedly check "is
// *p a valid digit" than "is p within bounds and *p a valid digit".
if (s.len >= 256) {
if (s.len > WUFFS_BASE__PARSE_NUMBER_XXX__SLICE_LEN_MAX_INCL) {
wuffs_base__result_f64 ret;
ret.status.repr = wuffs_base__error__bad_argument_length_too_long;
ret.value = 0;
return ret;
}
goto fallback;
}
uint8_t z[256];
+7
View File
@@ -174,6 +174,13 @@ fail_out_of_bounds:
WUFFS_BASE__MAYBE_STATIC wuffs_base__result_u64 //
wuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {
if (s.len > WUFFS_BASE__PARSE_NUMBER_XXX__SLICE_LEN_MAX_INCL) {
wuffs_base__result_u64 ret;
ret.status.repr = wuffs_base__error__bad_argument_length_too_long;
ret.value = 0;
return ret;
}
uint8_t* p = s.ptr;
uint8_t* q = s.ptr + s.len;
+8
View File
@@ -10,6 +10,14 @@
// ---------------- String Conversions
// WUFFS_BASE__PARSE_NUMBER_XXX__SLICE_LEN_MAX_INCL is the largest acceptible
// length for the wuffs_base__parse_number_xxx functions' slice argument.
//
// It equals ((1 << 20) - 1), which is one less than 1 MiB.
#define WUFFS_BASE__PARSE_NUMBER_XXX__SLICE_LEN_MAX_INCL 0xFFFFF
// --------
// Options (bitwise or'ed together) for wuffs_base__parse_number_xxx
// functions. The XXX options apply to both integer and floating point. The FXX
// options apply only to floating point.