diff --git a/src/core/operations/ToHexdump.mjs b/src/core/operations/ToHexdump.mjs index a52b0451..f73f2608 100644 --- a/src/core/operations/ToHexdump.mjs +++ b/src/core/operations/ToHexdump.mjs @@ -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); diff --git a/tests/operations/tests/Hexdump.mjs b/tests/operations/tests/Hexdump.mjs index 6eb486db..12d04492 100644 --- a/tests/operations/tests/Hexdump.mjs +++ b/tests/operations/tests/Hexdump.mjs @@ -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 ................