sidorares / sidorares/node-mysql2

error while parsing: "should not reach here"

Open
#655 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

~Snip stack:

    at Packet.readLengthCodedNumberExt (/node_modules/mysql2/lib/packets/packet.js:207:11)
    at Packet.readLengthCodedNumber (/node_modules/mysql2/lib/packets/packet.js:157:15)
    at Packet.parseLengthCodedInt (/node_modules/mysql2/lib/packets/packet.js:668:29)

I can't tell exactly what the problem is, but it seems like there's no bounds check on the Packet.readLengthCodedNumber function.

https://github.com/sidorares/node-mysql2/blob/b098d4969a000644d110e29b9aa0bee33cb1dfcb/lib/packets/packet.js#L152-L158

if offset is greater than buffer's length, then byte2 is set to undefined, which breaks the rest of the code.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/packets/packet.js around lines 152-158, then follow Packet.readLengthCodedNumber, readLengthCodedNumberExt, and parseLengthCodedInt from the reported stack trace. Use the case where offset exceeds the buffer length as the starting scenario; done means parsing no longer produces an undefined byte or reaches the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, node.js
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.