From 6fbbd39dbe5ec20c9776ac4789de10dcdc92dfaa Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 22 Dec 2016 11:28:12 +0100 Subject: file-zip: speed up data descriptor scanning Reduce time to process TechnicLauncher.jar from 20 to 9 seconds (ASAN build with tshark -Vx) by reducing TvbRange allocations. --- lua/file-zip.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lua/file-zip.lua b/lua/file-zip.lua index b50e62b..dcfb165 100644 --- a/lua/file-zip.lua +++ b/lua/file-zip.lua @@ -192,22 +192,22 @@ end -- Returns the length of the data and the length of the data descriptor. local function find_data_desc(tvb) local dd_offset = 0 - local length = tvb:len() + local data = tvb:raw(tvb:offset()) -- Scans (byte for byte) for the size field and try to confirm the validity -- of this length field. It might still have a false positive, but at least - -- it allows for a linear search. - while dd_offset + 8 < length do + -- it allows for a linear scan through the file (without consulting CD). + while dd_offset + 8 < #data do -- Size field is at offset 4 (if sig exists) or at offset 8 otherwise. local size_offset - if tvb(dd_offset, 4):le_uint() == 0x08074b50 then + if Struct.unpack(" #data then return end size_offset = dd_offset + 8 - -- If overflowing, size must be invalid. - if size_offset + 4 > length then return end else size_offset = dd_offset + 4 end -- Validata size or continue with next byte on failure. - local comp_size = tvb(size_offset, 4):le_uint() + local comp_size = Struct.unpack("