diff options
author | 2023-07-08 06:10:49 +0800 | |
---|---|---|
committer | 2023-07-07 15:10:49 -0700 | |
commit | c0cf7b4501efe579f0cbd6c2118c00df2ebc6a13 (patch) | |
tree | 58fe18bb47d12f7cf1e36fe53c550e29890ef79d /src/bun.js/bindings/JSStringDecoder.cpp | |
parent | affd06d05cc756df33854bc1d56e2284ff22b22d (diff) | |
download | bun-c0cf7b4501efe579f0cbd6c2118c00df2ebc6a13.tar.gz bun-c0cf7b4501efe579f0cbd6c2118c00df2ebc6a13.tar.zst bun-c0cf7b4501efe579f0cbd6c2118c00df2ebc6a13.zip |
fix decoding invalid UTF-8 input (#3563)
* fix decoding invalid UTF-8 input
Close: https://github.com/oven-sh/bun/issues/3562
* add unittest
Diffstat (limited to 'src/bun.js/bindings/JSStringDecoder.cpp')
-rw-r--r-- | src/bun.js/bindings/JSStringDecoder.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/bun.js/bindings/JSStringDecoder.cpp b/src/bun.js/bindings/JSStringDecoder.cpp index 5ec258522..b8c2dd50c 100644 --- a/src/bun.js/bindings/JSStringDecoder.cpp +++ b/src/bun.js/bindings/JSStringDecoder.cpp @@ -129,7 +129,7 @@ uint8_t JSStringDecoder::utf8CheckIncomplete(uint8_t* bufPtr, uint32_t length, u m_lastNeed = nb - 1; return nb; } - if (--j < i || nb == -2) + if (j == 0 || --j < i || nb == -2) return 0; nb = utf8CheckByte(bufPtr[j]); if (nb >= 0) { @@ -137,7 +137,7 @@ uint8_t JSStringDecoder::utf8CheckIncomplete(uint8_t* bufPtr, uint32_t length, u m_lastNeed = nb - 2; return nb; } - if (--j < i || nb == -2) + if (j == 0 || --j < i || nb == -2) return 0; nb = utf8CheckByte(bufPtr[j]); if (nb >= 0) { |