fix: clamp payload length in MMKVParser to prevent overflow

- Updated the MMKVParser to ensure the calculated length does not exceed the DataView's byte length.
- Added tests to verify behavior at the payload boundary, including cases for oversized payloads and exact matches.
This commit is contained in:
鲁树人 committed 2026-10-27 09:01:42 +09:00
1 parent 10e857a903
commit 75d786c747
2 files changed
+56 -1

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ export class MMKVParser {
constructor(private view: DataView<ArrayBuffer>) {
const payloadLength = view.getUint32(0, true);
this.length = 4 + payloadLength;
this.length = Math.min(4 + payloadLength, view.byteLength);
// skip unused str
this.readInt();