diff options
| author | Mike Pall <mike> | 2022-01-13 17:48:43 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2022-01-13 17:48:43 +0100 |
| commit | e56048753634c32ea6eeedf74cef6f9cfea5f4ed (patch) | |
| tree | 4f2edb808d55b3a2673a9bbc8149c40df492444f | |
| parent | 103c29e634d822e0affd7d3ae16a7d8a80c038d3 (diff) | |
| download | luajit-e56048753634c32ea6eeedf74cef6f9cfea5f4ed.tar.gz luajit-e56048753634c32ea6eeedf74cef6f9cfea5f4ed.tar.bz2 luajit-e56048753634c32ea6eeedf74cef6f9cfea5f4ed.zip | |
Limit exponent range in number parsing.
Reported by XmiliaH.
| -rw-r--r-- | src/lj_strscan.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/lj_strscan.c b/src/lj_strscan.c index d18fab8c..947d9746 100644 --- a/src/lj_strscan.c +++ b/src/lj_strscan.c | |||
| @@ -63,6 +63,7 @@ | |||
| 63 | #define STRSCAN_MAXDIG 800 /* 772 + extra are sufficient. */ | 63 | #define STRSCAN_MAXDIG 800 /* 772 + extra are sufficient. */ |
| 64 | #define STRSCAN_DDIG (STRSCAN_DIG/2) | 64 | #define STRSCAN_DDIG (STRSCAN_DIG/2) |
| 65 | #define STRSCAN_DMASK (STRSCAN_DDIG-1) | 65 | #define STRSCAN_DMASK (STRSCAN_DDIG-1) |
| 66 | #define STRSCAN_MAXEXP (1 << 20) | ||
| 66 | 67 | ||
| 67 | /* Helpers for circular buffer. */ | 68 | /* Helpers for circular buffer. */ |
| 68 | #define DNEXT(a) (((a)+1) & STRSCAN_DMASK) | 69 | #define DNEXT(a) (((a)+1) & STRSCAN_DMASK) |
| @@ -399,6 +400,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt) | |||
| 399 | if (dig) { | 400 | if (dig) { |
| 400 | ex = (int32_t)(dp-(p-1)); dp = p-1; | 401 | ex = (int32_t)(dp-(p-1)); dp = p-1; |
| 401 | while (ex < 0 && *dp-- == '0') ex++, dig--; /* Skip trailing zeros. */ | 402 | while (ex < 0 && *dp-- == '0') ex++, dig--; /* Skip trailing zeros. */ |
| 403 | if (ex <= -STRSCAN_MAXEXP) return STRSCAN_ERROR; | ||
| 402 | if (base == 16) ex *= 4; | 404 | if (base == 16) ex *= 4; |
| 403 | } | 405 | } |
| 404 | } | 406 | } |
| @@ -412,7 +414,8 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt) | |||
| 412 | if (!lj_char_isdigit(*p)) return STRSCAN_ERROR; | 414 | if (!lj_char_isdigit(*p)) return STRSCAN_ERROR; |
| 413 | xx = (*p++ & 15); | 415 | xx = (*p++ & 15); |
| 414 | while (lj_char_isdigit(*p)) { | 416 | while (lj_char_isdigit(*p)) { |
| 415 | if (xx < 65536) xx = xx * 10 + (*p & 15); | 417 | xx = xx * 10 + (*p & 15); |
| 418 | if (xx >= STRSCAN_MAXEXP) return STRSCAN_ERROR; | ||
| 416 | p++; | 419 | p++; |
| 417 | } | 420 | } |
| 418 | ex += negx ? -(int32_t)xx : (int32_t)xx; | 421 | ex += negx ? -(int32_t)xx : (int32_t)xx; |
