mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Fix gif parsing error on some gifs and add test
This commit is contained in:
parent
4ef5de2cce
commit
66ad95c330
@ -1,4 +1,5 @@
|
||||
# This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
|
||||
# The source was png.ksy from here - https://github.com/kaitai-io/kaitai_struct_formats/blob/562154250bea0081fed4e232751b934bc270a0c7/image/gif.ksy
|
||||
|
||||
import array
|
||||
import struct
|
||||
@ -28,24 +29,13 @@ class Gif(KaitaiStruct):
|
||||
if self.logical_screen_descriptor.has_color_table:
|
||||
self._raw_global_color_table = self._io.read_bytes((self.logical_screen_descriptor.color_table_size * 3))
|
||||
io = KaitaiStream(BytesIO(self._raw_global_color_table))
|
||||
self.global_color_table = self._root.GlobalColorTable(io, self, self._root)
|
||||
self.global_color_table = self._root.ColorTable(io, self, self._root)
|
||||
|
||||
self.blocks = []
|
||||
while not self._io.is_eof():
|
||||
self.blocks.append(self._root.Block(self._io, self, self._root))
|
||||
|
||||
|
||||
class GlobalColorTable(KaitaiStruct):
|
||||
def __init__(self, _io, _parent=None, _root=None):
|
||||
self._io = _io
|
||||
self._parent = _parent
|
||||
self._root = _root if _root else self
|
||||
self.entries = []
|
||||
while not self._io.is_eof():
|
||||
self.entries.append(self._root.ColorTableEntry(self._io, self, self._root))
|
||||
|
||||
|
||||
|
||||
class ImageData(KaitaiStruct):
|
||||
def __init__(self, _io, _parent=None, _root=None):
|
||||
self._io = _io
|
||||
@ -103,6 +93,11 @@ class Gif(KaitaiStruct):
|
||||
self.width = self._io.read_u2le()
|
||||
self.height = self._io.read_u2le()
|
||||
self.flags = self._io.read_u1()
|
||||
if self.has_color_table:
|
||||
self._raw_local_color_table = self._io.read_bytes((self.color_table_size * 3))
|
||||
io = KaitaiStream(BytesIO(self._raw_local_color_table))
|
||||
self.local_color_table = self._root.ColorTable(io, self, self._root)
|
||||
|
||||
self.image_data = self._root.ImageData(self._io, self, self._root)
|
||||
|
||||
@property
|
||||
@ -151,6 +146,17 @@ class Gif(KaitaiStruct):
|
||||
self.body = self._root.LocalImageDescriptor(self._io, self, self._root)
|
||||
|
||||
|
||||
class ColorTable(KaitaiStruct):
|
||||
def __init__(self, _io, _parent=None, _root=None):
|
||||
self._io = _io
|
||||
self._parent = _parent
|
||||
self._root = _root if _root else self
|
||||
self.entries = []
|
||||
while not self._io.is_eof():
|
||||
self.entries.append(self._root.ColorTableEntry(self._io, self, self._root))
|
||||
|
||||
|
||||
|
||||
class Header(KaitaiStruct):
|
||||
def __init__(self, _io, _parent=None, _root=None):
|
||||
self._io = _io
|
||||
|
@ -93,6 +93,13 @@ def test_parse_png(filename, metadata):
|
||||
('background', '248'),
|
||||
('comment', "b'Created with GIMP'")
|
||||
],
|
||||
# check working with color table
|
||||
"mitmproxy/data/image_parser/iss634.gif": [
|
||||
('Format', 'Compuserve GIF'),
|
||||
('version', 'GIF89a'),
|
||||
('Size', '245 x 245 px'),
|
||||
('background', '0')
|
||||
],
|
||||
}.items())
|
||||
def test_parse_gif(filename, metadata):
|
||||
with open(tutils.test_data.path(filename), 'rb') as f:
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 939 KiB |
BIN
test/mitmproxy/data/image_parser/iss634.gif
Normal file
BIN
test/mitmproxy/data/image_parser/iss634.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 271 KiB |
Loading…
Reference in New Issue
Block a user