Skip to content

Commit

Permalink
chore: separate code paths for ChunkTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain committed Jan 8, 2025
1 parent 96960e0 commit 6f7200d
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,29 @@ export class SnappyFramesUncompress {
case ChunkType.PADDING:
case ChunkType.SKIPPABLE:
continue;
case ChunkType.COMPRESSED:
case ChunkType.UNCOMPRESSED: {
case ChunkType.COMPRESSED: {
const checksum = frame.subarray(0, 4);
const data = frame.subarray(4);

const uncompressed = type === ChunkType.COMPRESSED ? uncompress(data, UNCOMPRESSED_CHUNK_SIZE) : data;
const uncompressed = uncompress(data, UNCOMPRESSED_CHUNK_SIZE);
if (crc(uncompressed).compare(checksum) !== 0) {
throw "malformed input: bad checksum";
}
result.append(uncompressed);
break;
}
case ChunkType.UNCOMPRESSED: {
const checksum = frame.subarray(0, 4);
const uncompressed = frame.subarray(4);

if (uncompressed.length > UNCOMPRESSED_CHUNK_SIZE) {
throw "malformed input: too large";
}
if (crc(uncompressed).compare(checksum) !== 0) {
throw "malformed input: bad checksum";
}
result.append(uncompressed);
break;
}
}
}
Expand Down

0 comments on commit 6f7200d

Please sign in to comment.