From eb90ee872ccbe27048b384a8b57b31c36d760454 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Thu, 16 Aug 2018 16:45:49 -0500 Subject: [PATCH] Fixed `GAPDataDecoder` --- Sources/GAPData.swift | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Sources/GAPData.swift b/Sources/GAPData.swift index ecc8046a6..d1f8cadda 100644 --- a/Sources/GAPData.swift +++ b/Sources/GAPData.swift @@ -215,12 +215,25 @@ public struct GAPDataDecoder { // get length let length = Int(data[index]) // 0 index += 1 - guard index < data.count - else { throw Error.insufficientBytes(expected: index + 1, actual: data.count) } + guard index < data.count else { + + if length == 0 { + + break // EOF + + } else { + + throw Error.insufficientBytes(expected: index + 1, actual: data.count) + } + } // get type let type = GAPDataType(rawValue: data[index]) // 1 + // ignore zeroed bytes + guard (type.rawValue == 0 && length == 0) == false + else { break } + // get value let value: Data