Skip to content

Commit c72a63f

Browse files
committed
Handle two-byte string alignment padding (rubyjs#333)
For compatibility with old clients of the serializer wire format, V8 inserts a padding byte when a two-byte string is not 16 bits aligned, so skip those. We don't have to emit padding ourselves, V8 handles unaligned strings just fine. Messages can have an arbitrary amount of padding at the end. Skip that as well. No test because hitting the right conditions in V8 is rather difficult and brittle.
1 parent b58853c commit c72a63f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

ext/mini_racer_extension/serde.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ static int des1(char (*err)[64], const uint8_t **p, const uint8_t *pe,
370370

371371
if (depth < 0)
372372
return bail(err, "too much recursion");
373+
again:
373374
if (*p >= pe)
374375
goto too_short;
375376
switch ((c = *(*p)++)) {
@@ -380,7 +381,9 @@ static int des1(char (*err)[64], const uint8_t **p, const uint8_t *pe,
380381
snprintf(*err, sizeof(*err), "bad tag: %02x", c);
381382
}
382383
return -1;
383-
case '\0': // padding
384+
case '\0': // skip alignment padding for two-byte strings
385+
if (*p < pe)
386+
goto again;
384387
break;
385388
case '^':
386389
if (r_varint(p, pe, &u))

0 commit comments

Comments
 (0)