From 6c038f5ca88f564dda78717ea6ae7f8ba3469670 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 18 Dec 2019 14:48:59 +0000 Subject: [PATCH] add a test for tuncated image files --- test/test-suite/helpers/helpers.py | 1 + test/test-suite/images/truncated.jpg | Bin 0 -> 10000 bytes test/test-suite/test_foreign.py | 15 ++++++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/test-suite/images/truncated.jpg diff --git a/test/test-suite/helpers/helpers.py b/test/test-suite/helpers/helpers.py index 628e9935..68343d00 100644 --- a/test/test-suite/helpers/helpers.py +++ b/test/test-suite/helpers/helpers.py @@ -9,6 +9,7 @@ import pyvips IMAGES = os.path.join(os.path.dirname(__file__), os.pardir, 'images') JPEG_FILE = os.path.join(IMAGES, "sample.jpg") +TRUNCATED_FILE = os.path.join(IMAGES, "truncated.jpg") SRGB_FILE = os.path.join(IMAGES, "sRGB.icm") MATLAB_FILE = os.path.join(IMAGES, "sample.mat") PNG_FILE = os.path.join(IMAGES, "sample.png") diff --git a/test/test-suite/images/truncated.jpg b/test/test-suite/images/truncated.jpg new file mode 100644 index 0000000000000000000000000000000000000000..71ae0bb487d12ca4c1e03b5ccacd63b37b4ba066 GIT binary patch literal 10000 zcmbW6cT`i`x9=0G^ctju-m8>QBB0U&p|{XMB-9|igCIqE=mZfE>Aeb}2zWs0olu2< zNJolFm1BE&&iTDF#=U>sci+s|S)Vo6%*^`EwO97e*uR#3tpjMaVQ?4#2m}Ct*Dt`Y z4}flsU^iy~01g)c+yDRoBmjCK;qRfp4pt!XU#;17pY0#EyJn$(VhFC8f#BbGw|Jtz z;;$3_W$&|y0DFW0z<*j203e+dKy*DODJ>-l%=nvu*BJms|M;aOC4ohMXZ-aG03ay( zJ0s8alnDRfSHGusZP&AxboKZ5zJ2SKr=P?FM=u8_38a_Dt>6dVx1=N_Zvp%scz8c_ z;tKZg=JNCRb@O!jwLzc`S5v!hXlww3>uUT}2m;9OTm-ZLfQP5Qud${omxZ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x+rwbf{F0F7*eGM8A| zI;G465l8~T{`I2gX`|Hf7?zFdduAu2>V=Y{G%So8D@%I*B3|!L>ClVHjU&(INuBo3 z8&Ux8TO&b_wYOxU{ePnCO1G(^zM8kdeFwm}ASXjb(_#JbP*!_VzSyCK!U95T4U`&q zRYXp~*lkEqpg2!gKrzoFk&a7ZI|Z&4DMDjntjXeg@4!;}iP-~OojmeDRil-2SNrWR zz#@XGf9S?YTc)8oimu>%r?i&gif5k4SnlH6!OHhvfE4q3qz{D#X*~$ZXi6<55U!!8 z`ygGEHQBUZXxI=~zKP{Is|=`++{t<^q-5-z6-Wmzjr1#+bHJqP5wxgTaSum4WX&r< zQ@yJe)e;qLrZMZUwfgh=Nv0~-UGzq?JdkUoxAvkXVLR1Op6KDCxJ9Q%Ny*`?;*xz3 zQ6um5)6N@TJbe0OU;L+MztjCprL-At(c)Pxlk1{b!b`}G zB5Iez!NF>mx_=0r$(o6d<2@2vQtS0R0zqAJncVaw2M5{{MYu~c_Dp{>s0dWH(nWgs z#zqUD(12|pf5&$b3kON1Xf9RIUKp#`A%&my!#ky?C7oZy*Y3{EXe4zOQ}qW)%k0u~ z_NZ?#)0HDwe)5o74ZQ5kqv*+uHbu*W=VOAl@zN4jgg=g3H-3&MhR?{hTs7$kyw5HG zxH+rGA~x;rjr6V0lXeHC4M!^pN6dQ~Z_LNNVS$m=3%xmQrVrE*-qt#D$yjk+zIW$* zpi#oWCT}0Rdvexls1Vo?$~_BzwWfu xnhn6@6@pi|IQ2z>SKMO|n>J6C+c|el5XZ#h1TssP73orW4?|A&WDVyt{|~n0v>yNf literal 0 HcmV?d00001 diff --git a/test/test-suite/test_foreign.py b/test/test-suite/test_foreign.py index a45da51b..94b4336b 100644 --- a/test/test-suite/test_foreign.py +++ b/test/test-suite/test_foreign.py @@ -11,7 +11,7 @@ from helpers import \ JPEG_FILE, SRGB_FILE, MATLAB_FILE, PNG_FILE, TIF_FILE, OME_FILE, \ ANALYZE_FILE, GIF_FILE, WEBP_FILE, EXR_FILE, FITS_FILE, OPENSLIDE_FILE, \ PDF_FILE, SVG_FILE, SVGZ_FILE, SVG_GZ_FILE, GIF_ANIM_FILE, DICOM_FILE, \ - BMP_FILE, NIFTI_FILE, ICO_FILE, HEIC_FILE, \ + BMP_FILE, NIFTI_FILE, ICO_FILE, HEIC_FILE, TRUNCATED_FILE, \ temp_filename, assert_almost_equal_objects, have, skip_if_no @@ -234,6 +234,19 @@ class TestForeign: # format area at the end assert y.startswith("hello world") + @skip_if_no("jpegload") + def test_truncated(self): + # This should open (there's enough there for the header) + im = pyvips.Image.new_from_file(TRUNCATED_FILE) + # but this should fail with a warning, and knock TRUNCATED_FILE out of + # the cache + x = im.avg() + + # now we should open again, but it won't come from cache, it'll reload + im = pyvips.Image.new_from_file(TRUNCATED_FILE) + # and this should fail with a warning once more + x = im.avg() + @skip_if_no("pngload") def test_png(self): def png_valid(im):