From cc4e195a0ea2dce88f2fd6c6d73b2504e3c884fd Mon Sep 17 00:00:00 2001 From: Abhishek Paul Date: Wed, 16 Jul 2025 10:32:37 +0530 Subject: [PATCH] long-cbor decode fix Signed-off-by: Abhishek Paul --- Sources/CBORDecoder.swift | 9 ++++++++- Tests/CBORDecoderTests.swift | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Sources/CBORDecoder.swift b/Sources/CBORDecoder.swift index 4e26806..8455ded 100644 --- a/Sources/CBORDecoder.swift +++ b/Sources/CBORDecoder.swift @@ -60,9 +60,16 @@ public class CBORDecoder { throw CBORError.tooLongSequence } + /// Application-safe limit here + let MAX_REASONABLE_LENGTH = 200_000 + guard n <= MAX_REASONABLE_LENGTH else { + throw CBORError.tooLongSequence + } + return Int(n) } + private func readN(_ n: Int) throws -> [CBOR] { return try (0..