From ea080e13ea962279b8bf9571cd40bf3123272bf3 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Wed, 15 Aug 2018 18:57:21 +0300 Subject: [PATCH] [XZ] Check size of LZMA2 filter properties and throw error if they are wrong --- Sources/XZ/XZBlock.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/XZ/XZBlock.swift b/Sources/XZ/XZBlock.swift index e87a685a..049d1786 100644 --- a/Sources/XZ/XZBlock.swift +++ b/Sources/XZ/XZBlock.swift @@ -41,8 +41,10 @@ struct XZBlock { else { throw XZError.wrongFilterID } // Only LZMA2 filter is supported. if filterID == 0x21 { - // First, we need to skip byte with the size of filter's properties - _ = try byteReader.multiByteDecode() + // First, we need to check if size of LZMA2 filter's properties is equal to 1 as expected. + let propertiesSize = try byteReader.multiByteDecode() + guard propertiesSize == 1 + else { throw LZMA2Error.wrongDictionarySize } /// In case of LZMA2 filters property is a dicitonary size. let filterPropeties = byteReader.byte() let closure = { (dwp: ByteReader) -> Data in