Skip to content

Commit 29a2f97

Browse files
authored
Fix OOB read in tag name array on corrupt input (#1019)
Happens only in debug builds because the bytecode deserializer trace logging is disabled in release builds (guarded on `#ifndef NDEBUG`) Fixes: #1017
1 parent a57877c commit 29a2f97

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

quickjs.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35224,6 +35224,13 @@ static const char * const bc_tag_str[] = {
3522435224
"Set",
3522535225
"Symbol",
3522635226
};
35227+
35228+
static const char *bc_tag_name(uint8_t tag)
35229+
{
35230+
if (tag >= countof(bc_tag_str))
35231+
return "<bad tag>";
35232+
return bc_tag_str[tag];
35233+
}
3522735234
#endif
3522835235

3522935236
static void bc_put_u8(BCWriterState *s, uint8_t v)
@@ -37077,7 +37084,7 @@ static JSValue JS_ReadObjectRec(BCReaderState *s)
3707737084
if (bc_get_u8(s, &tag))
3707837085
return JS_EXCEPTION;
3707937086

37080-
bc_read_trace(s, "%s {\n", bc_tag_str[tag]);
37087+
bc_read_trace(s, "%s {\n", bc_tag_name(tag));
3708137088

3708237089
switch(tag) {
3708337090
case BC_TAG_NULL:

0 commit comments

Comments
 (0)