From 65b35d84f8eceba4621dfdb2d435bec1bca4329b Mon Sep 17 00:00:00 2001 From: Sergii Tytarenko Date: Thu, 23 Aug 2018 18:51:21 +0300 Subject: [PATCH 1/2] Fix None value of comment --- src/PIL/GifImagePlugin.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index fec2f7663..a186afd0a 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -529,7 +529,8 @@ def _write_local_header(fp, im, offset, flags): o8(0)) if "comment" in im.encoderinfo and \ - 1 <= len(im.encoderinfo["comment"]) <= 255: + and im.encoderinfo["comment"] is not None \ + and 1 <= len(im.encoderinfo["comment"]) <= 255: fp.write(b"!" + o8(254) + # extension intro o8(len(im.encoderinfo["comment"])) + @@ -695,7 +696,8 @@ def _get_global_header(im, info): for extensionKey in ["transparency", "duration", "loop", "comment"]: if info and extensionKey in info: if ((extensionKey == "duration" and info[extensionKey] == 0) or - (extensionKey == "comment" and + (extensionKey == "comment" + and info[extensionKey] is not None and not (1 <= len(info[extensionKey]) <= 255))): continue version = b"89a" From ba8f59107d14f08d5d9b3a23602432c617a485b6 Mon Sep 17 00:00:00 2001 From: Sergii Tytarenko Date: Wed, 29 Aug 2018 11:51:06 +0300 Subject: [PATCH 2/2] Fix a syntax error --- src/PIL/GifImagePlugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index a186afd0a..0b33f68fb 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -528,8 +528,8 @@ def _write_local_header(fp, im, offset, flags): o8(transparency) + # transparency index o8(0)) - if "comment" in im.encoderinfo and \ - and im.encoderinfo["comment"] is not None \ + if "comment" in im.encoderinfo \ + and im.encoderinfo["comment"] is not None \ and 1 <= len(im.encoderinfo["comment"]) <= 255: fp.write(b"!" + o8(254) + # extension intro