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', () => {
379379 return Buffer . concat ( [ padding , header , contentBuf ] ) ;
380380 }
381381
382+ const MAX_INT_32 = 2147483648 ;
383+
382384 it ( 'should handle string just below 2^31 boundary' , function ( ) {
383385 this . timeout ( 15000 ) ;
384- const offset = 0x7ffffff0 ; // 2^31 - 16
386+ const offset = MAX_INT_32 - 16 ;
385387 const content = 'boundary test' ;
386388
387389 const buffer = createBufferWithStringAtOffset ( offset , content ) ;
@@ -398,7 +400,7 @@ describe('lib/decoder', () => {
398400
399401 it ( 'should handle when string at offset >= 2^31' , function ( ) {
400402 this . timeout ( 15000 ) ;
401- const offset = 0x80000000 ; // Exactly 2^31
403+ const offset = MAX_INT_32 ;
402404 const content = 'test' ;
403405
404406 const buffer = createBufferWithStringAtOffset ( offset , content ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ utils.assert(
66 'Apparently you are using old version of node. Please upgrade to node 10.4.x or above.'
77) ;
88
9+ const MAX_INT_32 = 2_147_483_647 ;
10+
911enum DataType {
1012 Extended = 0 ,
1113 Pointer = 1 ,
@@ -282,7 +284,7 @@ export default class Decoder {
282284
283285 private decodeString ( offset : number , size : number ) {
284286 const newOffset = offset + size ;
285- return newOffset >= 2147483648 // 2^31 Buffer.toString() limit
287+ return newOffset >= MAX_INT_32
286288 ? this . db . subarray ( offset , newOffset ) . toString ( 'utf8' )
287289 : this . db . toString ( 'utf8' , offset , newOffset ) ;
288290 }
You can’t perform that action at this time.
0 commit comments