File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -379,9 +379,11 @@ describe('lib/decoder', () => {
379
379
return Buffer . concat ( [ padding , header , contentBuf ] ) ;
380
380
}
381
381
382
+ const MAX_INT_32 = 2147483648 ;
383
+
382
384
it ( 'should handle string just below 2^31 boundary' , function ( ) {
383
385
this . timeout ( 15000 ) ;
384
- const offset = 0x7ffffff0 ; // 2^31 - 16
386
+ const offset = MAX_INT_32 - 16 ;
385
387
const content = 'boundary test' ;
386
388
387
389
const buffer = createBufferWithStringAtOffset ( offset , content ) ;
@@ -398,7 +400,7 @@ describe('lib/decoder', () => {
398
400
399
401
it ( 'should handle when string at offset >= 2^31' , function ( ) {
400
402
this . timeout ( 15000 ) ;
401
- const offset = 0x80000000 ; // Exactly 2^31
403
+ const offset = MAX_INT_32 ;
402
404
const content = 'test' ;
403
405
404
406
const buffer = createBufferWithStringAtOffset ( offset , content ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ utils.assert(
6
6
'Apparently you are using old version of node. Please upgrade to node 10.4.x or above.'
7
7
) ;
8
8
9
+ const MAX_INT_32 = 2_147_483_647 ;
10
+
9
11
enum DataType {
10
12
Extended = 0 ,
11
13
Pointer = 1 ,
@@ -282,7 +284,7 @@ export default class Decoder {
282
284
283
285
private decodeString ( offset : number , size : number ) {
284
286
const newOffset = offset + size ;
285
- return newOffset >= 2147483648 // 2^31 Buffer.toString() limit
287
+ return newOffset >= MAX_INT_32
286
288
? this . db . subarray ( offset , newOffset ) . toString ( 'utf8' )
287
289
: this . db . toString ( 'utf8' , offset , newOffset ) ;
288
290
}
You can’t perform that action at this time.
0 commit comments