From e107ed6fcfa5d8090115f1966b8427a4a808a3f7 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 22 Dec 2017 17:01:54 +1100 Subject: [PATCH] Allow for an empty line in EPS header data --- PIL/EpsImagePlugin.py | 81 +++++++++++++++-------------- Tests/images/zero_bb_emptyline.eps | Bin 0 -> 26360 bytes Tests/test_file_eps.py | 10 ++++ 3 files changed, 52 insertions(+), 39 deletions(-) create mode 100644 Tests/images/zero_bb_emptyline.eps diff --git a/PIL/EpsImagePlugin.py b/PIL/EpsImagePlugin.py index e6842e91e..044d089bf 100644 --- a/PIL/EpsImagePlugin.py +++ b/PIL/EpsImagePlugin.py @@ -227,53 +227,56 @@ class EpsImageFile(ImageFile.ImageFile): # # Load EPS header - s = fp.readline().strip('\r\n') + s_raw = fp.readline() + s = s_raw.strip('\r\n') - while s: - if len(s) > 255: - raise SyntaxError("not an EPS file") + while s_raw: + if s: + if len(s) > 255: + raise SyntaxError("not an EPS file") - try: - m = split.match(s) - except re.error as v: - raise SyntaxError("not an EPS file") + try: + m = split.match(s) + except re.error as v: + raise SyntaxError("not an EPS file") - if m: - k, v = m.group(1, 2) - self.info[k] = v - if k == "BoundingBox": - try: - # Note: The DSC spec says that BoundingBox - # fields should be integers, but some drivers - # put floating point values there anyway. - box = [int(float(i)) for i in v.split()] - self.size = box[2] - box[0], box[3] - box[1] - self.tile = [("eps", (0, 0) + self.size, offset, - (length, box))] - except: - pass - - else: - m = field.match(s) if m: - k = m.group(1) + k, v = m.group(1, 2) + self.info[k] = v + if k == "BoundingBox": + try: + # Note: The DSC spec says that BoundingBox + # fields should be integers, but some drivers + # put floating point values there anyway. + box = [int(float(i)) for i in v.split()] + self.size = box[2] - box[0], box[3] - box[1] + self.tile = [("eps", (0, 0) + self.size, offset, + (length, box))] + except: + pass - if k == "EndComments": - break - if k[:8] == "PS-Adobe": - self.info[k[:8]] = k[9:] - else: - self.info[k] = "" - elif s[0] == '%': - # handle non-DSC Postscript comments that some - # tools mistakenly put in the Comments section - pass else: - raise IOError("bad EPS header") + m = field.match(s) + if m: + k = m.group(1) - s = fp.readline().strip('\r\n') + if k == "EndComments": + break + if k[:8] == "PS-Adobe": + self.info[k[:8]] = k[9:] + else: + self.info[k] = "" + elif s[0] == '%': + # handle non-DSC Postscript comments that some + # tools mistakenly put in the Comments section + pass + else: + raise IOError("bad EPS header") - if s[:1] != "%": + s_raw = fp.readline() + s = s_raw.strip('\r\n') + + if s and s[:1] != "%": break # diff --git a/Tests/images/zero_bb_emptyline.eps b/Tests/images/zero_bb_emptyline.eps new file mode 100644 index 0000000000000000000000000000000000000000..4f4bb7103457b683ec59d949aeedf8046b865e60 GIT binary patch literal 26360 zcmcItdvDvumjB!Q6th?uaQ0RdxaOrtL<_&U)~+BzP=WK6XC!YL0{q3 z&&%1#>Vcq$oa5+jzP#A17OOk&2qews(?qELK=8#Zy7khBH#E}Q_x8p0eI#yIi^b{- zFo|Vle<_vOdiEeB%;|o0p&N3;(oH6iTSOVMe%$S%?`~J+vPkFi}^AV zU*@yqUeKt!&EzqjP8N}vKTPf-aW{E*n270Wvx%k&B*K#e*NQMqG4UPG=N+AZgALOH zG`HT-@nSOlltf<>p-JP1SF6Q*W?435(S7fH>|pM75UGQxC5&m-FizkKOln-Iuao~1fjsPMo<6&`cq@1WGmMvl2Wa+JQz(~7Dr=eKA_O!9 zC%zYbpZXP-svH0p9*m(dfuiQw^VsCr#uxaWjYGF`sARNz-aSycAEH^3eBq zS|0nWcuECP2Kis{lyPYzI1x{Alx*&9rsTu+o7)VDxScN+_NzMvqHtk9eH-7ezTgdh zvME6^`{G>3BSfC)7Mhre1;XS;%$FjeKsJXlLOU@$bhSyuyX!Z-5jD6#;d*mPMu zFb_pGVm~|67>&`dSMy~e;$*Y>6p3>fx^bjSZ!Zr>Pj~U;bA*@Rnivo~#T~)}@0^!@1UZf7$R`an zNd6$yAo+v7rX!zYP((ZAISvC0&j@3XwA*dL9ZY zH4r`)iV#bC2;@gY=%o}vIz-t+AW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_^Nn8Pfzbwb(A|ttU zWuJY!RC2gf*+$jtqchT0H`$3o4Pb>xUj@Ehn!+J!`+)vPC7PBf$=j4?4e!Hd5n@{q z*cFPdsY?Jwo>7lt2~1&}>(TOZsK5fPAJh=kP>oDszr=)#!PYhVQCl#e3fWME6@e_T zl?(G***Y&X8x7VbNe6?rm8=styOox?rh6m!gF*>gunm_FE*1^nHN|2<6ILqfarQ!C zT0l{Nuyhxo@aqL_Ih!kFlkTWOmf*b^1$8z93a)6pLIg0`mVm&&T&iEFs_j9TUWE(Ku%F)iYeHwOO?Yo z7QZTNW5d!0tdP1^Z4egY+?sFA_BJ2X2uDW=CbBPRdqDbW$^F!%vQHL;k61_9_qVps zZ^gg!icE?QFltOlT2<+z%Ai@#<` zRC1p)&T=@h7&i}?dreCf_c^x}pD;sOMGUzeIZ%pv%P2H0e<*+Sv>?VJ@v(yYuE!JUoL@V{R3X^OIMCwXi3^~ghjx$T zHE{<6;ML9unYWX1VwHd9SF4x(;Co9 z7+)TU|1JdNDWHdLCW^uL9(e|OYT|NdA~fxRnfGQxPav>t-oNv-2~NFG@ic0)A&qMnfi7S zE%B|D`g+`gM^O$TG$#ynGeFaT`*oRQEtA?!1nrN}2bCi%Ei6gdSauL5omzyP*9KRG|HVwUw)FlVa0&pB literal 0 HcmV?d00001 diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index 70930bf95..2313b292c 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -278,6 +278,16 @@ class TestFileEps(PillowTestCase): # Assert self.assertEqual(img.mode, "RGB") + def test_emptyline(self): + # Test file includes an empty line in the header data + emptyline_file = "Tests/images/zero_bb_emptyline.eps" + + image = Image.open(emptyline_file) + image.load() + self.assertEqual(image.mode, "RGB") + self.assertEqual(image.size, (460, 352)) + self.assertEqual(image.format, "EPS") + if __name__ == '__main__': unittest.main()