Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bun v0.7.3 crashes with node-mysql2 module, works fine in v0.7.0 #4119

Closed
brynne8 opened this issue Aug 11, 2023 · 5 comments
Closed

Bun v0.7.3 crashes with node-mysql2 module, works fine in v0.7.0 #4119

brynne8 opened this issue Aug 11, 2023 · 5 comments
Labels
bug Something isn't working crash An issue that could cause a crash node.js Compatibility with Node.js APIs

Comments

@brynne8
Copy link

brynne8 commented Aug 11, 2023

What version of Bun is running?

0.7.3

What platform is your computer?

Linux 5.14.0-284.11.1.el9_2.x86_64 x86_64 x86_64

What steps can reproduce the bug?

  1. Set up a new Bun project with v0.7.3.
  2. Install the node-mysql2 module.
  3. Use the following code:
import { Router } from '@stricjs/router'
const mysql = require('mysql2/promise');

const pool = await mysql.createPool({
  ...
});

const app = new Router({ port: 8000 })
    .get('/', () => new Response('JS-based server'))
    .get('/order/:id', async () => {
        const [rows] = await pool.query(`SELECT * FROM tb_xxx WHERE id = ?`, [ req.params.id ]);
        return Response.json(rows);
    });

Bun.serve(app);

What is the expected behavior?

The application should run without any issues, and the routes should be accessible.

What do you see instead?

The application crashes when visiting /order with the error Trace/breakpoint trap (core dumped).

Additional information

  • The issue does not occur in Bun v0.7.0.
  • It seems the bug only appears when using prepared statements in mysql2
@brynne8 brynne8 added the bug Something isn't working label Aug 11, 2023
@Jarred-Sumner
Copy link
Collaborator

Stack trace:

59 |   static fromPacket(packet) {
60 |     const args = {};
61 |     console.log(packet)
62 |     args.protocolVersion = packet.readInt8();
63 |     args.serverVersion = packet.readNullTerminatedString('cesu8');
64 |     args.connectionId = packet.readInt32();
                            ^
RangeError: Out of bounds access
      at fromPacket (node_modules/mysql2/lib/packets/handshake.js:64:24)
      at handshakeInit (node_modules/mysql2/lib/commands/client_handshake.js:112:21)
      at execute (node_modules/mysql2/lib/commands/command.js:45:16)
      at handlePacket (node_modules/mysql2/lib/connection.js:478:19)
      at node_modules/mysql2/lib/connection.js:97:6
      at executeStart (node_modules/mysql2/lib/packet_parser.js:75:10)
      at node_modules/mysql2/lib/connection.js:104:6
      at addChunk (node:stream:1803:46)

The message Out of bounds access comes from the DataView used internally by the Buffer object contained in packet

@brynne8
Copy link
Author

brynne8 commented Aug 14, 2023

Will this be fixed soon? Or do you need further comments?

@Jarred-Sumner
Copy link
Collaborator

@brynne8 I suspect it's a library bug and that this code worked in an earlier version of Bun is a bug

The below snippet based on your snippet doesn't run successfully in Node:
image

const mysql = require("mysql2/promise");

async function main() {
  const pool = await mysql.createPool({
    host: "localhost",
    port: 33060,
    user: "root",
    password: "ZlwyV9dQM0?p",
  });

  const { fields } = await pool.query(`SELECT * FROM tb_xxx WHERE id = ?`, [1]);
  console.log(fields);
}

main();

@melroy89
Copy link

melroy89 commented Sep 23, 2023

ZlwyV9dQM0?p

Do did just exposed your local password of user root of the database (ZlwyV9dQM0?p). Just saying..

@Electroid Electroid added the node.js Compatibility with Node.js APIs label Oct 26, 2023
@Jarred-Sumner
Copy link
Collaborator

We run integration tests for mysql2 in CI nowadays, so I'm pretty confident this particular issue is fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crash An issue that could cause a crash node.js Compatibility with Node.js APIs
Projects
None yet
Development

No branches or pull requests

5 participants