summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Hupp <adam@hupp.org>2019-12-11 22:13:58 -0800
committerAdam Hupp <adam@hupp.org>2019-12-11 22:13:58 -0800
commit8852eafff7c8d0b386a6b648fff5b51602014f2b (patch)
treed721873f6aa6532eba5cf49f3f085ac5e40cf66a
parentcc346b83b55d97eb473599e0f2b5fd355a11b35f (diff)
downloadpython-magic-8852eafff7c8d0b386a6b648fff5b51602014f2b.tar.gz
Fix https://github.com/ahupp/python-magic/issues/190
-rw-r--r--magic.py9
-rwxr-xr-xtest/run.sh2
-rwxr-xr-xtest/test.py5
-rw-r--r--test/testdata/python-3.7.2-python-magic-0.4.15.jpgbin0 -> 1722401 bytes
4 files changed, 15 insertions, 1 deletions
diff --git a/magic.py b/magic.py
index 07f7096..699e461 100644
--- a/magic.py
+++ b/magic.py
@@ -65,6 +65,15 @@ class Magic:
magic_load(self.cookie, magic_file)
+
+ # For https://github.com/ahupp/python-magic/issues/190
+ # libmagic has fixed internal limits that some files exceed, causing
+ # an error. We can avoid this (at least for the sample file given)
+ # by bumping the limit up. It's not clear if this is a general solution
+ # or whether other internal limits should be increased, but given
+ # the lack of other reports I'll assume this is rare.
+ self.setparam(MAGIC_PARAM_NAME_MAX, 64)
+
def from_buffer(self, buf):
"""
Identify the contents of `buf`
diff --git a/test/run.sh b/test/run.sh
index 63698ab..ebd7976 100755
--- a/test/run.sh
+++ b/test/run.sh
@@ -7,7 +7,7 @@ export LC_ALL=en_US.UTF-8
THISDIR=`dirname $0`
export PYTHONPATH=${THISDIR}/..
-PYTHONS="python2.7 python3.5"
+PYTHONS="python2.7 python3.5 python3.7"
for pyver in $PYTHONS; do
if which $pyver > /dev/null; then
diff --git a/test/test.py b/test/test.py
index 0f3aac2..3d835c1 100755
--- a/test/test.py
+++ b/test/test.py
@@ -148,5 +148,10 @@ class MagicTest(unittest.TestCase):
m.setparam(magic.MAGIC_PARAM_INDIR_MAX, 1)
self.assertEqual(m.getparam(magic.MAGIC_PARAM_INDIR_MAX), 1)
+ def test_name_count(self):
+ m = magic.Magic()
+ with open('testdata/python-3.7.2-python-magic-0.4.15.jpg', 'rb') as f:
+ m.from_buffer(f.read())
+
if __name__ == '__main__':
unittest.main()
diff --git a/test/testdata/python-3.7.2-python-magic-0.4.15.jpg b/test/testdata/python-3.7.2-python-magic-0.4.15.jpg
new file mode 100644
index 0000000..e2dc2d7
--- /dev/null
+++ b/test/testdata/python-3.7.2-python-magic-0.4.15.jpg
Binary files differ