diff --git a/src/core/blitz/readDVPL.ts b/src/core/blitz/readDVPL.ts index 85812065f..fff0c81d0 100644 --- a/src/core/blitz/readDVPL.ts +++ b/src/core/blitz/readDVPL.ts @@ -9,13 +9,13 @@ import { decodeBlock } from 'lz4'; */ export async function readDVPL(file: string) { const buffer = await readFile(file); - const footerBuffer = buffer.slice(buffer.length - 20, buffer.length); + const footerBuffer = buffer.subarray(buffer.length - 20, buffer.length); if ( footerBuffer.toString('utf8', 16, 20) !== 'DVPL' || footerBuffer.length !== 20 ) { - throw 'InvalidDVPLFooter'; + throw new SyntaxError('Invalid DVPL footer'); } const footerData = { @@ -24,13 +24,17 @@ export async function readDVPL(file: string) { crc32: footerBuffer.readUInt32LE(8), type: footerBuffer.readUInt32LE(12), }; - const targetBlock = buffer.slice(0, buffer.length - 20); + const targetBlock = buffer.subarray(0, buffer.length - 20); - if (targetBlock.length !== footerData.cSize) throw 'DVPLSizeMismatch'; - if (crc32(targetBlock) !== footerData.crc32) throw 'DVPLCRC32Mismatch'; + if (targetBlock.length !== footerData.cSize) { + throw new RangeError('DVPL size mismatch'); + } + if (crc32(targetBlock) !== footerData.crc32) { + throw new TypeError('DVPL CRC32 mismatch'); + } if (footerData.type === 0) { if (!(footerData.oSize === footerData.cSize && footerData.type === 0)) { - throw 'DVPLTypeSizeMismatch'; + throw new RangeError('DVPL type and size mismatch'); } return targetBlock; @@ -39,11 +43,11 @@ export async function readDVPL(file: string) { const DecompressedBlockSize = decodeBlock(targetBlock, deDVPLBlock); if (DecompressedBlockSize !== footerData.oSize) { - throw 'DVPLDecodeSizeMismatch'; + throw new RangeError('Decompressed DVPL size mismatch'); } return deDVPLBlock; } else { - throw new TypeError('Unknown DVPL format'); + throw new SyntaxError('Unknown DVPL format'); } }