aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSachin Kelkar <sachinkel19@gmail.com>2017-02-08 00:03:07 +0530
committerSachin Kelkar <sachinkel19@gmail.com>2017-02-08 00:03:07 +0530
commit66ad95c33009e394d949f20791e196d6d077bb5c (patch)
treeaca7fdfad0424b68d3c1f206403fbd13dfbee1b9
parent4ef5de2cce6bc794b760102f2a5b82dd28d078c0 (diff)
downloadmitmproxy-66ad95c33009e394d949f20791e196d6d077bb5c.tar.gz
mitmproxy-66ad95c33009e394d949f20791e196d6d077bb5c.tar.bz2
mitmproxy-66ad95c33009e394d949f20791e196d6d077bb5c.zip
Fix gif parsing error on some gifs and add test
-rw-r--r--mitmproxy/contrib/kaitaistruct/gif.py30
-rw-r--r--test/mitmproxy/contentviews/test_image_parser.py7
-rw-r--r--test/mitmproxy/data/image_parser/aspect.gifbin961994 -> 0 bytes
-rw-r--r--test/mitmproxy/data/image_parser/iss634.gifbin0 -> 277517 bytes
4 files changed, 25 insertions, 12 deletions
diff --git a/mitmproxy/contrib/kaitaistruct/gif.py b/mitmproxy/contrib/kaitaistruct/gif.py
index 0a68b815..3a847d54 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 997392dc..4241a1bb 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 56690231..00000000
--- a/test/mitmproxy/data/image_parser/aspect.gif
+++ /dev/null
Binary files differ
diff --git a/test/mitmproxy/data/image_parser/iss634.gif b/test/mitmproxy/data/image_parser/iss634.gif
new file mode 100644
index 00000000..ba4e4566
--- /dev/null
+++ b/test/mitmproxy/data/image_parser/iss634.gif
Binary files differ