diff --git a/mitmproxy/contrib/kaitaistruct/gif.py b/mitmproxy/contrib/kaitaistruct/gif.py index 0a68b8150..3a847d540 100644 --- a/mitmproxy/contrib/kaitaistruct/gif.py +++ b/mitmproxy/contrib/kaitaistruct/gif.py @@ -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 diff --git a/test/mitmproxy/contentviews/test_image_parser.py b/test/mitmproxy/contentviews/test_image_parser.py index 997392dc0..4241a1bb3 100644 --- a/test/mitmproxy/contentviews/test_image_parser.py +++ b/test/mitmproxy/contentviews/test_image_parser.py @@ -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: diff --git a/test/mitmproxy/data/image_parser/aspect.gif b/test/mitmproxy/data/image_parser/aspect.gif deleted file mode 100644 index 566902317..000000000 Binary files a/test/mitmproxy/data/image_parser/aspect.gif and /dev/null differ diff --git a/test/mitmproxy/data/image_parser/iss634.gif b/test/mitmproxy/data/image_parser/iss634.gif new file mode 100644 index 000000000..ba4e4566f Binary files /dev/null and b/test/mitmproxy/data/image_parser/iss634.gif differ