Skip to content

Commit

Permalink
Handle two-byte string alignment padding (#333)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bnoordhuis authored Jan 11, 2025
1 parent d42fc2d commit 9874a17
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ext/mini_racer_extension/serde.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ static int des1(char (*err)[64], const uint8_t **p, const uint8_t *pe,

if (depth < 0)
return bail(err, "too much recursion");
again:
if (*p >= pe)
goto too_short;
switch ((c = *(*p)++)) {
Expand All @@ -380,7 +381,9 @@ static int des1(char (*err)[64], const uint8_t **p, const uint8_t *pe,
snprintf(*err, sizeof(*err), "bad tag: %02x", c);
}
return -1;
case '\0': // padding
case '\0': // skip alignment padding for two-byte strings
if (*p < pe)
goto again;
break;
case '^':
if (r_varint(p, pe, &u))
Expand Down

0 comments on commit 9874a17

Please sign in to comment.