fix(native): bound cross-platform lifecycle ownership

This commit is contained in:
edde746
2026-07-24 03:56:40 +02:00
parent 09656fa4d3
commit 9f2e050797
98 changed files with 12908 additions and 1599 deletions
+26
View File
@@ -50,4 +50,30 @@ void main() {
expect(MpvNodeDecoder.decodeMap(testCase.input), testCase.map);
});
}
test('rejects hostile structured payloads before traversal', () {
Object? acceptedDepth = 'leaf';
for (var i = 0; i < 31; i++) {
acceptedDepth = [acceptedDepth];
}
expect(MpvNodeDecoder.decodeList(acceptedDepth), isNotNull);
Object? excessiveDepth = acceptedDepth;
excessiveDepth = [excessiveDepth];
expect(MpvNodeDecoder.decodeList(excessiveDepth), isNull);
expect(MpvNodeDecoder.decodeList(List<Object?>.filled(16384, null)), isNull);
expect(MpvNodeDecoder.decodeList([double.nan]), isNull);
expect(MpvNodeDecoder.decodeMap({1: 'non-string key'}), isNull);
});
test('preflights deeply nested and oversized JSON', () {
final deepestAccepted = '${List.filled(31, '[').join()}null${List.filled(31, ']').join()}';
final tooDeep = '[$deepestAccepted]';
expect(MpvNodeDecoder.decodeList(deepestAccepted), isNotNull);
expect(MpvNodeDecoder.decodeList(tooDeep), isNull);
final tooManyEntries = '[${List.filled(16385, 'null').join(',')}]';
expect(MpvNodeDecoder.decodeList(tooManyEntries), isNull);
expect(MpvNodeDecoder.decodeList('["brackets [ and braces { stay quoted"]'), isNotNull);
});
}