fix decoding invalid UTF-8 input (#3563)

* fix decoding invalid UTF-8 input
Close: https://github.com/oven-sh/bun/issues/3562

* add unittest
This commit is contained in:
Ai Hoshino
2023-07-08 06:10:49 +08:00
committed by GitHub
parent affd06d05c
commit c0cf7b4501
2 changed files with 11 additions and 2 deletions

View File

@@ -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) {