Skip to content

writeUIntBE() method does not throw range error for 48bit  #30420

@arpadpall21

Description

@arpadpall21
  • Version 13.1.0:
  • Platform 64-bit Windows 10:
  • Subsystem buffer:

The writeUIntBE() method does not throw a Range Error if we pass a higher than allowed 48bit unsigned integer value

var buf = Buffer.alloc(6);

buf.writeUIntBE(281474976710655, 0, 6);             // largest possible 48bit Unsigned Integer 
console.log( buf.readUIntBE(0, 6) );                // -> 281474976710655     // written value returned 
console.log( buf );                                 // -> <Buffer ff ff ff ff ff ff>

buf.writeUIntBE(281474976710656, 0, 6);             // no [ERR_OUT_OF_RANGE] thrown
console.log( buf.readUIntBE(0, 6) );                // -> 0                   // unexpected value returned  
    console.log( buf );                             // -> <Buffer 00 00 00 00 00 00>

buf.writeUIntBE(3000000000000000, 0, 6);            // no [ERR_OUT_OF_RANGE] thrown
console.log( buf.readUIntBE(0, 6) );                // -> 185250232893440     // unexpected value returned
    console.log( buf );                             // -> <Buffer a8 7b ee 53 80 00>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions