node-firebird 2.3.1 → 2.3.3

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.
Files changed (55) hide show
  1. package/README.md +218 -31
  2. package/lib/index.d.ts +22 -0
  3. package/lib/pool.js +97 -10
  4. package/lib/srp.js +12 -1
  5. package/lib/wire/connection.js +40 -7
  6. package/lib/wire/socket.js +13 -1
  7. package/lib/wire/xsqlvar.js +69 -6
  8. package/package.json +1 -1
  9. package/poc/README.md +160 -0
  10. package/poc/helpers.js +59 -0
  11. package/poc/node_modules/.package-lock.json +14 -0
  12. package/poc/node_modules/node-firebird/.eslintrc.json +12 -0
  13. package/poc/node_modules/node-firebird/.github/workflows/codeql.yml +76 -0
  14. package/poc/node_modules/node-firebird/.github/workflows/node.js.yml +95 -0
  15. package/poc/node_modules/node-firebird/BIGINT_MIGRATION.md +374 -0
  16. package/poc/node_modules/node-firebird/CI_DEBUGGING_GUIDE.md +148 -0
  17. package/poc/node_modules/node-firebird/ENCRYPTION_CALLBACK.md +152 -0
  18. package/poc/node_modules/node-firebird/FIREBIRD_LOG_FEATURE.md +145 -0
  19. package/poc/node_modules/node-firebird/LICENSE +373 -0
  20. package/poc/node_modules/node-firebird/MINIMAL_CHANGES_SUMMARY.md +136 -0
  21. package/poc/node_modules/node-firebird/PR_SUMMARY.md +96 -0
  22. package/poc/node_modules/node-firebird/README.md +794 -0
  23. package/poc/node_modules/node-firebird/ROADMAP.md +223 -0
  24. package/poc/node_modules/node-firebird/SRP_PROTOCOL.md +482 -0
  25. package/poc/node_modules/node-firebird/lib/callback.js +38 -0
  26. package/poc/node_modules/node-firebird/lib/firebird.msg +0 -0
  27. package/poc/node_modules/node-firebird/lib/firebird.msg.json +1371 -0
  28. package/poc/node_modules/node-firebird/lib/gdscodes.d.ts +1524 -0
  29. package/poc/node_modules/node-firebird/lib/gdscodes.js +1531 -0
  30. package/poc/node_modules/node-firebird/lib/ieee754-decimal.js +500 -0
  31. package/poc/node_modules/node-firebird/lib/index.d.ts +316 -0
  32. package/poc/node_modules/node-firebird/lib/index.js +128 -0
  33. package/poc/node_modules/node-firebird/lib/messages.js +162 -0
  34. package/poc/node_modules/node-firebird/lib/pool.js +108 -0
  35. package/poc/node_modules/node-firebird/lib/srp.js +299 -0
  36. package/poc/node_modules/node-firebird/lib/unix-crypt.js +343 -0
  37. package/poc/node_modules/node-firebird/lib/utils.js +164 -0
  38. package/poc/node_modules/node-firebird/lib/wire/connection.js +2510 -0
  39. package/poc/node_modules/node-firebird/lib/wire/const.js +807 -0
  40. package/poc/node_modules/node-firebird/lib/wire/database.js +378 -0
  41. package/poc/node_modules/node-firebird/lib/wire/eventConnection.js +118 -0
  42. package/poc/node_modules/node-firebird/lib/wire/fbEventManager.js +326 -0
  43. package/poc/node_modules/node-firebird/lib/wire/serialize.js +588 -0
  44. package/poc/node_modules/node-firebird/lib/wire/service.js +1058 -0
  45. package/poc/node_modules/node-firebird/lib/wire/socket.js +175 -0
  46. package/poc/node_modules/node-firebird/lib/wire/statement.js +48 -0
  47. package/poc/node_modules/node-firebird/lib/wire/transaction.js +206 -0
  48. package/poc/node_modules/node-firebird/lib/wire/xsqlvar.js +703 -0
  49. package/poc/node_modules/node-firebird/package.json +38 -0
  50. package/poc/node_modules/node-firebird/vitest.config.js +24 -0
  51. package/poc/package-lock.json +21 -0
  52. package/poc/package.json +12 -0
  53. package/poc/reproduce-fixed.js +150 -0
  54. package/poc/reproduce.js +133 -0
  55. package/vitest.config.js +4 -1
@@ -0,0 +1,588 @@
1
+
2
+ const { encodeDecimal64, decodeDecimal64, encodeDecimal128, decodeDecimal128 } = require('../ieee754-decimal');
3
+
4
+ function align(n) {
5
+ return (n + 3) & ~3;
6
+ }
7
+
8
+ /***************************************
9
+ *
10
+ * BLR Writer
11
+ *
12
+ ***************************************/
13
+
14
+ const
15
+ MAX_STRING_SIZE = 255;
16
+
17
+ class BlrWriter {
18
+ constructor(size) {
19
+ this.buffer = Buffer.alloc(size || 32);
20
+ this.pos = 0;
21
+ }
22
+
23
+ ensure(len) {
24
+ var newlen = this.buffer.length;
25
+
26
+ while (newlen < this.pos + len)
27
+ newlen *= 2
28
+
29
+ if (this.buffer.length >= newlen)
30
+ return;
31
+
32
+ var b = Buffer.alloc(newlen);
33
+ this.buffer.copy(b);
34
+ delete(this.buffer);
35
+ this.buffer = b;
36
+ }
37
+
38
+ addByte(b) {
39
+ this.ensure(1);
40
+ this.buffer.writeUInt8(b, this.pos);
41
+ this.pos++;
42
+ }
43
+
44
+ addShort(b) {
45
+ this.ensure(1);
46
+ this.buffer.writeInt8(b, this.pos);
47
+ this.pos++;
48
+ }
49
+
50
+ addSmall(b) {
51
+ this.ensure(2);
52
+ this.buffer.writeInt16LE(b, this.pos);
53
+ this.pos += 2;
54
+ }
55
+
56
+ addWord(b) {
57
+ this.ensure(2);
58
+ this.buffer.writeUInt16LE(b, this.pos);
59
+ this.pos += 2;
60
+ }
61
+
62
+ addInt32(b) {
63
+ this.ensure(4);
64
+ this.buffer.writeUInt32LE(b, this.pos);
65
+ this.pos += 4;
66
+ }
67
+
68
+ addByteInt32(c, b) {
69
+ this.addByte(c);
70
+ this.ensure(4);
71
+ this.buffer.writeUInt32LE(b, this.pos);
72
+ this.pos += 4;
73
+ }
74
+
75
+ addNumeric(c, v) {
76
+ if (v < 256){
77
+ this.ensure(3);
78
+ this.buffer.writeUInt8(c, this.pos);
79
+ this.pos++;
80
+ this.buffer.writeUInt8(1, this.pos);
81
+ this.pos++;
82
+ this.buffer.writeUInt8(v, this.pos);
83
+ this.pos++;
84
+ return;
85
+ }
86
+
87
+ this.ensure(6);
88
+ this.buffer.writeUInt8(c, this.pos);
89
+ this.pos++;
90
+ this.buffer.writeUInt8(4, this.pos);
91
+ this.pos++;
92
+ this.buffer.writeInt32BE(v, this.pos);
93
+ this.pos += 4;
94
+ }
95
+
96
+ addBytes(b) {
97
+ this.ensure(b.length);
98
+ for (var i = 0, length = b.length; i < length; i++) {
99
+ this.buffer.writeUInt8(b[i], this.pos);
100
+ this.pos++;
101
+ }
102
+ }
103
+
104
+ addString(c, s, encoding) {
105
+ this.addByte(c);
106
+
107
+ var len = Buffer.byteLength(s, encoding);
108
+ if (len > MAX_STRING_SIZE)
109
+ throw new Error('blr string is too big');
110
+
111
+ this.ensure(len + 1);
112
+ this.buffer.writeUInt8(len, this.pos);
113
+ this.pos++;
114
+ this.buffer.write(s, this.pos, len, encoding);
115
+ this.pos += len;
116
+ }
117
+
118
+ addBuffer(b) {
119
+ this.addWord(b.length);
120
+ this.ensure(b.length);
121
+ b.copy(this.buffer, this.pos);
122
+ this.pos += b.length;
123
+ }
124
+
125
+ addString2(c, s, encoding) {
126
+ this.addByte(c);
127
+
128
+ var len = Buffer.byteLength(s, encoding);
129
+ if (len > MAX_STRING_SIZE* MAX_STRING_SIZE)
130
+ throw new Error('blr string is too big');
131
+
132
+ this.ensure(len + 2);
133
+ this.buffer.writeUInt16LE(len, this.pos);
134
+ this.pos += 2;
135
+ this.buffer.write(s, this.pos, len, encoding);
136
+ this.pos += len;
137
+ }
138
+
139
+ addMultiblockPart(c, s, encoding) {
140
+ var buff = Buffer.from(s, encoding);
141
+ var remaining = buff.length;
142
+ var step = 0;
143
+
144
+ while (remaining > 0) {
145
+ var toWrite = Math.min(remaining, 254);
146
+
147
+ this.addByte(c);
148
+ this.addByte(toWrite + 1);
149
+ this.addByte(step);
150
+
151
+ this.ensure(toWrite);
152
+ buff.copy(this.buffer, this.pos, step * 254, (step * 254) + toWrite);
153
+
154
+ step++;
155
+ remaining -= toWrite;
156
+ this.pos += toWrite;
157
+ }
158
+ }
159
+ }
160
+
161
+ /***************************************
162
+ *
163
+ * BLR Reader
164
+ *
165
+ ***************************************/
166
+
167
+ class BlrReader {
168
+ constructor(buffer) {
169
+ this.buffer = buffer;
170
+ this.pos = 0;
171
+ }
172
+
173
+ readByteCode() {
174
+ return this.buffer.readUInt8(this.pos++);
175
+ }
176
+
177
+ readInt32() {
178
+ var value = this.buffer.readUInt32LE(this.pos);
179
+ this.pos += 4;
180
+ return value;
181
+ }
182
+
183
+ readInt() {
184
+ var len = this.buffer.readUInt16LE(this.pos);
185
+ this.pos += 2;
186
+ var value;
187
+ switch (len) {
188
+ case 1:
189
+ value = this.buffer.readInt8(this.pos);
190
+ break;
191
+ case 2:
192
+ value = this.buffer.readInt16LE(this.pos);
193
+ break;
194
+ case 4:
195
+ value = this.buffer.readInt32LE(this.pos)
196
+ }
197
+ this.pos += len;
198
+ return value;
199
+ }
200
+
201
+ readString(encoding) {
202
+ var len = this.buffer.readUInt16LE(this.pos);
203
+ var str;
204
+
205
+ this.pos += 2;
206
+ if (len <= 0)
207
+ return '';
208
+
209
+ str = this.buffer.toString(encoding, this.pos, this.pos + len);
210
+ this.pos += len;
211
+ return str;
212
+ }
213
+
214
+ readSegment() {
215
+ var ret, tmp;
216
+ var len = this.buffer.readUInt16LE(this.pos);
217
+
218
+ this.pos += 2;
219
+
220
+ while (len > 0) {
221
+
222
+ if (ret) {
223
+ tmp = ret;
224
+ ret = Buffer.alloc(tmp.length + len);
225
+ tmp.copy(ret);
226
+ this.buffer.copy(ret, tmp.length, this.pos, this.pos + len);
227
+ } else {
228
+ ret = Buffer.alloc(len);
229
+ this.buffer.copy(ret, 0, this.pos, this.pos + len);
230
+ }
231
+
232
+ this.pos += len;
233
+
234
+ if (this.pos === this.buffer.length)
235
+ break;
236
+
237
+ len = this.buffer.readUInt16LE(this.pos);
238
+ this.pos += 2;
239
+ }
240
+
241
+ return ret ? ret : Buffer.alloc(0);
242
+ }
243
+ }
244
+
245
+ /***************************************
246
+ *
247
+ * XDR Writer
248
+ *
249
+ ***************************************/
250
+
251
+ class XdrWriter {
252
+ constructor(size) {
253
+ this.buffer = Buffer.alloc(size || 32);
254
+ this.pos = 0;
255
+ }
256
+
257
+ ensure(len) {
258
+ var newlen = this.buffer.length;
259
+
260
+ while (newlen < this.pos + len)
261
+ newlen *= 2
262
+
263
+ if (this.buffer.length >= newlen)
264
+ return;
265
+
266
+ var b = Buffer.alloc(newlen);
267
+ this.buffer.copy(b);
268
+ delete(this.buffer);
269
+ this.buffer = b;
270
+ }
271
+
272
+ addInt(value) {
273
+ this.ensure(4);
274
+ this.buffer.writeInt32BE(value, this.pos);
275
+ this.pos += 4;
276
+ }
277
+
278
+ addInt64(value) {
279
+ this.ensure(8);
280
+ // Note: precision is limited to Number.MAX_SAFE_INTEGER (±2^53-1).
281
+ // Values outside this range lose precision, which matches the previous
282
+ // Long.fromNumber() behaviour.
283
+ this.buffer.writeBigInt64BE(BigInt(Math.trunc(value)), this.pos);
284
+ this.pos += 8;
285
+ }
286
+
287
+ addInt128(value) {
288
+ this.ensure(16);
289
+
290
+ const bigValue = BigInt(value);
291
+
292
+ const high = bigValue >> BigInt(64);
293
+ const low = bigValue & BigInt("0xFFFFFFFFFFFFFFFF");
294
+
295
+ this.buffer.writeBigUInt64BE(high, this.pos);
296
+ this.pos += 8;
297
+ this.buffer.writeBigUInt64BE(low, this.pos);
298
+ this.pos += 8;
299
+ }
300
+
301
+ addDecFloat16(value) {
302
+ // DECFLOAT(16) - IEEE 754 Decimal64 - 8 bytes
303
+ // Full IEEE 754-2008 Decimal64 implementation
304
+ this.ensure(8);
305
+
306
+ const encoded = encodeDecimal64(value);
307
+ encoded.copy(this.buffer, this.pos, 0, 8);
308
+ this.pos += 8;
309
+ }
310
+
311
+ addDecFloat34(value) {
312
+ // DECFLOAT(34) - IEEE 754 Decimal128 - 16 bytes
313
+ // Full IEEE 754-2008 Decimal128 implementation
314
+ this.ensure(16);
315
+
316
+ const encoded = encodeDecimal128(value);
317
+ encoded.copy(this.buffer, this.pos, 0, 16);
318
+ this.pos += 16;
319
+ }
320
+
321
+ addUInt(value) {
322
+ this.ensure(4);
323
+ this.buffer.writeUInt32BE(value, this.pos);
324
+ this.pos += 4;
325
+ }
326
+
327
+ addString(s, encoding) {
328
+ var len = Buffer.byteLength(s, encoding);
329
+ var alen = align(len);
330
+ this.ensure(alen + 4);
331
+ this.buffer.writeInt32BE(len, this.pos);
332
+ this.pos += 4;
333
+ this.buffer.write(s, this.pos, len, encoding);
334
+ this.pos += alen;
335
+ }
336
+
337
+ addText(s, encoding) {
338
+ var len = Buffer.byteLength(s, encoding);
339
+ var alen = align(len);
340
+ this.ensure(alen);
341
+ this.buffer.write(s, this.pos, len, encoding);
342
+ this.pos += alen;
343
+ }
344
+
345
+ addBlr(blr) {
346
+ var alen = align(blr.pos);
347
+ this.ensure(alen + 4);
348
+ this.buffer.writeInt32BE(blr.pos, this.pos);
349
+ this.pos += 4;
350
+ blr.buffer.copy(this.buffer, this.pos);
351
+ this.pos += alen;
352
+ }
353
+
354
+ getData() {
355
+ return this.buffer.slice(0, this.pos);
356
+ }
357
+
358
+ addDouble(value) {
359
+ this.ensure(8);
360
+ this.buffer.writeDoubleBE(value, this.pos);
361
+ this.pos += 8;
362
+ }
363
+
364
+ addQuad(quad) {
365
+ this.ensure(8);
366
+ var b = this.buffer;
367
+ b.writeInt32BE(quad.high, this.pos);
368
+ this.pos += 4;
369
+ b.writeInt32BE(quad.low, this.pos);
370
+ this.pos += 4;
371
+ }
372
+
373
+ addBuffer(buffer) {
374
+ this.ensure(buffer.length);
375
+ buffer.copy(this.buffer, this.pos, 0, buffer.length);
376
+ this.pos += buffer.length;
377
+ }
378
+
379
+ addAlignment(len) {
380
+ var alen = (4 - len) & 3;
381
+
382
+ this.ensure(alen);
383
+ this.buffer.write('ffffff', this.pos, alen, 'hex');
384
+ this.pos += alen;
385
+ }
386
+ }
387
+
388
+ /***************************************
389
+ *
390
+ * XDR Reader
391
+ *
392
+ ***************************************/
393
+
394
+ class XdrReader {
395
+ constructor(buffer) {
396
+ this.buffer = buffer;
397
+ this.pos = 0;
398
+ }
399
+
400
+ readInt() {
401
+ var r = this.buffer.readInt32BE(this.pos);
402
+ this.pos += 4;
403
+ return r;
404
+ }
405
+
406
+ readUInt() {
407
+ var r = this.buffer.readUInt32BE(this.pos);
408
+ this.pos += 4;
409
+ return r;
410
+ }
411
+
412
+ readInt64() {
413
+ // Note: precision is limited to Number.MAX_SAFE_INTEGER (±2^53-1).
414
+ // Values outside this range lose precision, which matches the previous
415
+ // Long(low, high).toNumber() behaviour.
416
+ const result = Number(this.buffer.readBigInt64BE(this.pos));
417
+ this.pos += 8;
418
+ return result;
419
+ }
420
+
421
+ readInt128() {
422
+ var high = this.buffer.readBigUInt64BE(this.pos)
423
+ this.pos += 8
424
+
425
+ var low = this.buffer.readBigUInt64BE(this.pos)
426
+ this.pos += 8
427
+
428
+ return (BigInt(high) << BigInt(64)) + BigInt(low)
429
+ }
430
+
431
+ readDecFloat16() {
432
+ // DECFLOAT(16) - IEEE 754 Decimal64 - 8 bytes
433
+ // Full IEEE 754-2008 Decimal64 implementation
434
+ const buf = this.buffer.slice(this.pos, this.pos + 8);
435
+ this.pos += 8;
436
+
437
+ return decodeDecimal64(buf);
438
+ }
439
+
440
+ readDecFloat34() {
441
+ // DECFLOAT(34) - IEEE 754 Decimal128 - 16 bytes
442
+ // Full IEEE 754-2008 Decimal128 implementation
443
+ const buf = this.buffer.slice(this.pos, this.pos + 16);
444
+ this.pos += 16;
445
+
446
+ return decodeDecimal128(buf);
447
+ }
448
+
449
+ readShort() {
450
+ var r = this.buffer.readInt16BE(this.pos);
451
+ this.pos += 2;
452
+ return r;
453
+ }
454
+
455
+ readQuad() {
456
+ var b = this.buffer;
457
+ var high = b.readInt32BE(this.pos);
458
+ this.pos += 4;
459
+ var low = b.readInt32BE(this.pos);
460
+ this.pos += 4;
461
+ return {low: low, high: high}
462
+ }
463
+
464
+ readFloat() {
465
+ var r = this.buffer.readFloatBE(this.pos);
466
+ this.pos += 4;
467
+ return r;
468
+ }
469
+
470
+ readDouble() {
471
+ var r = this.buffer.readDoubleBE(this.pos);
472
+ this.pos += 8;
473
+ return r;
474
+ }
475
+
476
+ readArray() {
477
+ var len = this.readInt();
478
+ if (!len)
479
+ return;
480
+ var r = this.buffer.slice(this.pos, this.pos + len);
481
+ this.pos += align(len);
482
+ return r;
483
+ }
484
+
485
+ readBuffer(len, toAlign = true) {
486
+ if (!arguments.length) {
487
+ len = this.readInt();
488
+ }
489
+
490
+ if (len !== null && len !== undefined) {
491
+
492
+ if (len <= 0){
493
+ return Buffer.alloc(0);
494
+ }
495
+
496
+ var r = this.buffer.slice(this.pos, this.pos + len);
497
+ this.pos += toAlign ? align(len) : len;
498
+ return r;
499
+ }
500
+ }
501
+
502
+ readString(encoding) {
503
+ var len = this.readInt();
504
+ return this.readText(len, encoding);
505
+ }
506
+
507
+ readText(len, encoding) {
508
+ if (len <= 0)
509
+ return '';
510
+
511
+ var r = this.buffer.toString(encoding, this.pos, this.pos + len);
512
+ this.pos += align(len);
513
+ return r;
514
+ }
515
+ }
516
+
517
+ /***************************************
518
+ *
519
+ * BitSet
520
+ *
521
+ ***************************************/
522
+ var WORD_LOG = 5;
523
+ var BUFFER_BITS = 8;
524
+ var BIT_ON = 1;
525
+ var BIT_OFF = 0;
526
+
527
+ class BitSet {
528
+ constructor(buffer) {
529
+ this.data = [];
530
+
531
+ if (buffer) {
532
+ this.scale(buffer.length * BUFFER_BITS);
533
+
534
+ for (var i = 0; i < buffer.length; i++) {
535
+ var n = buffer[i];
536
+
537
+ for (var j = 0; j < BUFFER_BITS; j++) {
538
+ var k = i * BUFFER_BITS + j;
539
+ this.data[k >>> WORD_LOG] |= (n >> j & BIT_ON) << k;
540
+ }
541
+ }
542
+ }
543
+ }
544
+
545
+ scale(index) {
546
+ var l = index >>> WORD_LOG;
547
+
548
+ for (var i = this.data.length; l >= i; l--) {
549
+ this.data.push(BIT_OFF);
550
+ }
551
+ }
552
+
553
+ set(index, value) {
554
+ let pos = index >>> 3;
555
+
556
+ for (let i = this.data.length; pos >= i; pos--) {
557
+ this.data.push(BIT_OFF);
558
+ }
559
+
560
+ pos = index >>> 3;
561
+
562
+ if (value === undefined || value) {
563
+ this.data[pos] |= (1 << (index % BUFFER_BITS));
564
+ } else {
565
+ this.data[pos] &= ~(1 << (index % BUFFER_BITS));
566
+ }
567
+ }
568
+
569
+ get(index) {
570
+ var n = index >>> WORD_LOG;
571
+
572
+ if (n >= this.data.length) {
573
+ return BIT_OFF;
574
+ }
575
+
576
+ return (this.data[n] >>> index) & BIT_ON;
577
+ }
578
+
579
+ toBuffer() {
580
+ return Buffer.from(this.data);
581
+ }
582
+ }
583
+
584
+ exports.BlrWriter = BlrWriter;
585
+ exports.BlrReader = BlrReader;
586
+ exports.XdrWriter = XdrWriter;
587
+ exports.XdrReader = XdrReader;
588
+ exports.BitSet = BitSet;