mysql2 3.19.0 → 3.19.1-canary.18692157

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -277,7 +277,10 @@ class ConnectionConfig {
277
277
  user: decodeURIComponent(parsedUrl.username),
278
278
  password: decodeURIComponent(parsedUrl.password),
279
279
  };
280
- parsedUrl.searchParams.forEach((value, key) => {
280
+ for (const [key, value] of parsedUrl.searchParams) {
281
+ if (key in options) {
282
+ continue;
283
+ }
281
284
  try {
282
285
  // Try to parse this as a JSON expression first
283
286
  options[key] = JSON.parse(value);
@@ -285,7 +288,7 @@ class ConnectionConfig {
285
288
  // Otherwise assume it is a plain string
286
289
  options[key] = value;
287
290
  }
288
- });
291
+ }
289
292
  return options;
290
293
  }
291
294
  }
@@ -406,8 +406,8 @@ class Packet {
406
406
  readNullTerminatedString(encoding) {
407
407
  const start = this.offset;
408
408
  let end = this.offset;
409
- while (this.buffer[end]) {
410
- end = end + 1; // TODO: handle OOB check
409
+ while (end < this.end && this.buffer[end] !== 0x00) {
410
+ end = end + 1;
411
411
  }
412
412
  this.offset = end + 1;
413
413
  return StringParser.decode(this.buffer, encoding, start, end);
@@ -516,16 +516,20 @@ class Packet {
516
516
  return result * sign;
517
517
  }
518
518
 
519
- // copy-paste from https://github.com/mysqljs/mysql/blob/master/lib/protocol/Parser.js
519
+ // adapted from https://github.com/mysqljs/mysql/blob/dc9c152a87ec51a1f647447268917243d2eab1fd/lib/protocol/Parser.js
520
520
  parseGeometryValue() {
521
521
  const buffer = this.readLengthCodedBuffer();
522
522
  let offset = 4;
523
523
  if (buffer === null || !buffer.length) {
524
524
  return null;
525
525
  }
526
+ const bufferLength = buffer.length;
526
527
  function parseGeometry() {
527
- let x, y, i, j, numPoints, line;
528
+ let x, y, i, j, numPoints, numRings, num, line;
528
529
  let result = null;
530
+ if (offset + 5 > bufferLength) {
531
+ return null;
532
+ }
529
533
  const byteOrder = buffer.readUInt8(offset);
530
534
  offset += 1;
531
535
  const wkbType = byteOrder
@@ -534,6 +538,9 @@ class Packet {
534
538
  offset += 4;
535
539
  switch (wkbType) {
536
540
  case 1: // WKBPoint
541
+ if (offset + 16 > bufferLength) {
542
+ return null;
543
+ }
537
544
  x = byteOrder
538
545
  ? buffer.readDoubleLE(offset)
539
546
  : buffer.readDoubleBE(offset);
@@ -545,12 +552,21 @@ class Packet {
545
552
  result = { x: x, y: y };
546
553
  break;
547
554
  case 2: // WKBLineString
555
+ if (offset + 4 > bufferLength) {
556
+ return null;
557
+ }
548
558
  numPoints = byteOrder
549
559
  ? buffer.readUInt32LE(offset)
550
560
  : buffer.readUInt32BE(offset);
551
561
  offset += 4;
562
+ if (numPoints > (bufferLength - offset) / 16) {
563
+ return null;
564
+ }
552
565
  result = [];
553
566
  for (i = numPoints; i > 0; i--) {
567
+ if (offset + 16 > bufferLength) {
568
+ break;
569
+ }
554
570
  x = byteOrder
555
571
  ? buffer.readDoubleLE(offset)
556
572
  : buffer.readDoubleBE(offset);
@@ -563,19 +579,30 @@ class Packet {
563
579
  }
564
580
  break;
565
581
  case 3: // WKBPolygon
566
- // eslint-disable-next-line no-case-declarations
567
- const numRings = byteOrder
582
+ if (offset + 4 > bufferLength) {
583
+ return null;
584
+ }
585
+ numRings = byteOrder
568
586
  ? buffer.readUInt32LE(offset)
569
587
  : buffer.readUInt32BE(offset);
570
588
  offset += 4;
589
+ if (numRings > (bufferLength - offset) / 4) {
590
+ return null;
591
+ }
571
592
  result = [];
572
593
  for (i = numRings; i > 0; i--) {
594
+ if (offset + 4 > bufferLength) {
595
+ break;
596
+ }
573
597
  numPoints = byteOrder
574
598
  ? buffer.readUInt32LE(offset)
575
599
  : buffer.readUInt32BE(offset);
576
600
  offset += 4;
577
601
  line = [];
578
602
  for (j = numPoints; j > 0; j--) {
603
+ if (offset + 16 > bufferLength) {
604
+ break;
605
+ }
579
606
  x = byteOrder
580
607
  ? buffer.readDoubleLE(offset)
581
608
  : buffer.readDoubleBE(offset);
@@ -593,11 +620,16 @@ class Packet {
593
620
  case 5: // WKBMultiLineString
594
621
  case 6: // WKBMultiPolygon
595
622
  case 7: // WKBGeometryCollection
596
- // eslint-disable-next-line no-case-declarations
597
- const num = byteOrder
623
+ if (offset + 4 > bufferLength) {
624
+ return null;
625
+ }
626
+ num = byteOrder
598
627
  ? buffer.readUInt32LE(offset)
599
628
  : buffer.readUInt32BE(offset);
600
629
  offset += 4;
630
+ if (num > (bufferLength - offset) / 9) {
631
+ return null;
632
+ }
601
633
  result = [];
602
634
  for (i = num; i > 0; i--) {
603
635
  result.push(parseGeometry());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysql2",
3
- "version": "3.19.0",
3
+ "version": "3.19.1-canary.18692157",
4
4
  "description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS",
5
5
  "main": "index.js",
6
6
  "typings": "typings/mysql/index",
@@ -15,8 +15,8 @@
15
15
  "test:bun:parallel": "bun poku -c=\"poku.config.mjs\" test",
16
16
  "test:bun:global": "cross-env SUITE=global bun poku -c=\"poku.config.mjs\" test/global",
17
17
  "test:deno": "npm run test:deno:parallel && npm run test:deno:global",
18
- "test:deno:parallel": "deno run --allow-read --allow-env --allow-run npm:poku@canary -c=\"poku.config.mjs\" test",
19
- "test:deno:global": "cross-env SUITE=global deno run --allow-read --allow-env --allow-run npm:poku@canary -c=\"poku.config.mjs\" test/global",
18
+ "test:deno:parallel": "deno run --allow-read --allow-env --allow-run npm:poku -c=\"poku.config.mjs\" test",
19
+ "test:deno:global": "cross-env SUITE=global deno run --allow-read --allow-env --allow-run npm:poku -c=\"poku.config.mjs\" test/global",
20
20
  "test:docker:up": "docker compose -f test/docker-compose.yml up --abort-on-container-exit --remove-orphans",
21
21
  "test:docker:down": "docker compose -f test/docker-compose.yml down",
22
22
  "test:docker:node": "npm run test:docker:up -- node && npm run test:docker:down",
@@ -87,7 +87,7 @@
87
87
  "eslint-plugin-async-await": "^0.0.0",
88
88
  "eslint-plugin-prettier": "^5.5.5",
89
89
  "globals": "^17.3.0",
90
- "poku": "^3.0.3-canary.8f374795",
90
+ "poku": "^4.0.0",
91
91
  "portfinder": "^1.0.38",
92
92
  "prettier": "^3.8.1",
93
93
  "tsx": "^4.21.0",