Skip to content

Commit 8852eaf

Browse files
committed
Fix ahupp#190
1 parent cc346b8 commit 8852eaf

4 files changed

Lines changed: 15 additions & 1 deletion

File tree

magic.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ def __init__(self, mime=False, magic_file=None, mime_encoding=False,
6565

6666
magic_load(self.cookie, magic_file)
6767

68+
69+
# For https://github.com/ahupp/python-magic/issues/190
70+
# libmagic has fixed internal limits that some files exceed, causing
71+
# an error. We can avoid this (at least for the sample file given)
72+
# by bumping the limit up. It's not clear if this is a general solution
73+
# or whether other internal limits should be increased, but given
74+
# the lack of other reports I'll assume this is rare.
75+
self.setparam(MAGIC_PARAM_NAME_MAX, 64)
76+
6877
def from_buffer(self, buf):
6978
"""
7079
Identify the contents of `buf`

test/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export LC_ALL=en_US.UTF-8
77
THISDIR=`dirname $0`
88
export PYTHONPATH=${THISDIR}/..
99

10-
PYTHONS="python2.7 python3.5"
10+
PYTHONS="python2.7 python3.5 python3.7"
1111

1212
for pyver in $PYTHONS; do
1313
if which $pyver > /dev/null; then

test/test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,10 @@ def test_getparam(self):
148148
m.setparam(magic.MAGIC_PARAM_INDIR_MAX, 1)
149149
self.assertEqual(m.getparam(magic.MAGIC_PARAM_INDIR_MAX), 1)
150150

151+
def test_name_count(self):
152+
m = magic.Magic()
153+
with open('testdata/python-3.7.2-python-magic-0.4.15.jpg', 'rb') as f:
154+
m.from_buffer(f.read())
155+
151156
if __name__ == '__main__':
152157
unittest.main()
1.64 MB
Loading

0 commit comments

Comments
 (0)