fix: validate hexdump width upper bound (#2514)
This commit is contained in:
parent
92ea854ea7
commit
7f0544e1c6
@ -8,6 +8,8 @@ import Operation from "../Operation.mjs";
|
||||
import Utils from "../Utils.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
const MAX_WIDTH = 65536;
|
||||
|
||||
/**
|
||||
* To Hexdump operation
|
||||
*/
|
||||
@ -30,7 +32,8 @@ class ToHexdump extends Operation {
|
||||
"name": "Width",
|
||||
"type": "number",
|
||||
"value": 16,
|
||||
"min": 1
|
||||
"min": 1,
|
||||
"max": MAX_WIDTH
|
||||
},
|
||||
{
|
||||
"name": "Upper case hex",
|
||||
@ -63,6 +66,9 @@ class ToHexdump extends Operation {
|
||||
if (length < 1 || Math.round(length) !== length)
|
||||
throw new OperationError("Width must be a positive integer");
|
||||
|
||||
if (length > MAX_WIDTH)
|
||||
throw new OperationError(`Width must be no more than ${MAX_WIDTH}`);
|
||||
|
||||
const lines = [];
|
||||
for (let i = 0; i < data.length; i += length) {
|
||||
let lineNo = Utils.hex(i, 8);
|
||||
|
||||
@ -126,6 +126,17 @@ TestRegister.addTests([
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Hexdump: Width too large",
|
||||
input: "H",
|
||||
expectedOutput: "Width must be no more than 65536",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Hexdump",
|
||||
args: [155555555555555, false, false, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Hexdump: xxd",
|
||||
input: `00000000: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f ................
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user