Skip to content

MBS-14308: Fix readUInt32LE RangeError in the template renderer#3741

Open
mwiencek wants to merge 1 commit into
metabrainz:masterfrom
mwiencek:mbs-14308
Open

MBS-14308: Fix readUInt32LE RangeError in the template renderer#3741
mwiencek wants to merge 1 commit into
metabrainz:masterfrom
mwiencek:mbs-14308

Conversation

@mwiencek
Copy link
Copy Markdown
Member

Problem

MBS-14308

Solution

This commit was written with the help of kiro-cli, which uses a variety of models underneath. Here's what it had to say, which I think is useful:

"The bug is clear. When a new data chunk arrives and recvBuffer is null, the code assumes the first 4 bytes are always present in that chunk to read the UInt32LE length prefix. But TCP is a stream — a chunk can arrive with fewer than 4 bytes, causing readUInt32LE(0) to throw RangeError: Attempt to access memory outside buffer bounds."

Initially, the model suggested a different fix which added additional allocations, and after some back-and-forth, I got it to produce some code which reads the header byte-by-byte. I wrote the comments and chose the variable name.

AI usage

See above.

Testing

While I'm not sure how to reliably trigger the bug through normal browsing, I had the AI generate a script which triggers the issue, which helped me verify that the fix worked. Didn't notice any other change in browsing various pages. I also added logging on both the Perl & JS sides to verify that the number of bytes sent by Perl still matches the expectedBytes on the JS side.

This commit was written with the help of kiro-cli, which uses a variety of
models underneath. Here's what it had to say, which I think is useful:

"The bug is clear. When a new data chunk arrives and recvBuffer is null, the
code assumes the first 4 bytes are always present in that chunk to read the
UInt32LE length prefix. But TCP is a stream — a chunk can arrive with fewer
than 4 bytes, causing readUInt32LE(0) to throw RangeError: Attempt to access
memory outside buffer bounds."

Initially, the model suggested a different fix which added additional
allocations, and after some back-and-forth, I got it to produce some code which
reads the header byte-by-byte. I wrote the comments and chose the variable
name.

While I'm not sure how to reliably trigger the bug through normal browsing, I
had the AI generate a script which triggers the issue, which helped me verify
that the fix worked.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant