From 2d14c7ea434393f6c9a7a86ac051b5d191e12034 Mon Sep 17 00:00:00 2001 From: tannerdsilva Date: Mon, 18 Mar 2024 19:15:39 -0500 Subject: [PATCH] optimized overflow logic --- Sources/HummingbirdCore/Utils/HBParser.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/HummingbirdCore/Utils/HBParser.swift b/Sources/HummingbirdCore/Utils/HBParser.swift index 89ae55b9d..b09342e6d 100644 --- a/Sources/HummingbirdCore/Utils/HBParser.swift +++ b/Sources/HummingbirdCore/Utils/HBParser.swift @@ -596,13 +596,9 @@ extension Parser { func _percentDecode(_ original: ArraySlice, _ bytes: UnsafeMutableBufferPointer) throws -> Int { var newIndex = 0 var index = original.startIndex - - while index < original.endIndex { + while index < (original.endIndex - 2) { // if we have found a percent sign if original[index] == 0x25 { - guard original.endIndex - index >= 2 else { - throw DecodeError() - } let high = Self.asciiHexValues[Int(original[index + 1])] let low = Self.asciiHexValues[Int(original[index + 2])] index += 3 @@ -617,9 +613,13 @@ extension Parser { index += 1 } } + while index < original.endIndex { + bytes[newIndex] = original[index] + newIndex += 1 + index += 1 + } return newIndex } - guard self.index != self.range.endIndex else { return "" } do { if #available(macOS 11, macCatalyst 14.0, iOS 14.0, tvOS 14.0, *) {