{
    "file_diffs": [
        {
            "old_file_content": "import sys\nfrom io import StringIO\n\nfrom PIL import Image, IptcImagePlugin\n\nfrom .helper import hopper\n\nTEST_FILE = \"Tests/images/iptc.jpg\"\n\n\ndef test_getiptcinfo_jpg_none():\n    # Arrange\n    with hopper() as im:\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n    # Assert\n    assert iptc is None\n\n\ndef test_getiptcinfo_jpg_found():\n    # Arrange\n    with Image.open(TEST_FILE) as im:\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n    # Assert\n    assert isinstance(iptc, dict)\n    assert iptc[(2, 90)] == b\"Budapest\"\n    assert iptc[(2, 101)] == b\"Hungary\"\n\n\ndef test_getiptcinfo_tiff_none():\n    # Arrange\n    with Image.open(\"Tests/images/hopper.tif\") as im:\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n    # Assert\n    assert iptc is None\n\n\ndef test_i():\n    # Arrange\n    c = b\"a\"\n\n    # Act\n    ret = IptcImagePlugin.i(c)\n\n    # Assert\n    assert ret == 97\n\n\ndef test_dump():\n    # Arrange\n    c = b\"abc\"\n    # Temporarily redirect stdout\n    old_stdout = sys.stdout\n    sys.stdout = mystdout = StringIO()\n\n    # Act\n    IptcImagePlugin.dump(c)\n\n    # Reset stdout\n    sys.stdout = old_stdout\n\n    # Assert\n    assert mystdout.getvalue() == \"61 62 63 \\n\"\n",
            "new_file_content": "import sys\nfrom io import StringIO\n\nfrom PIL import Image, IptcImagePlugin\n\nfrom .helper import hopper\n\nTEST_FILE = \"Tests/images/iptc.jpg\"\n\n\ndef test_getiptcinfo_jpg_none():\n    # Arrange\n    with hopper() as im:\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n    # Assert\n    assert iptc is None\n\n\ndef test_getiptcinfo_jpg_found():\n    # Arrange\n    with Image.open(TEST_FILE) as im:\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n    # Assert\n    assert isinstance(iptc, dict)\n    assert iptc[(2, 90)] == b\"Budapest\"\n    assert iptc[(2, 101)] == b\"Hungary\"\n\n\ndef test_getiptcinfo_zero_padding():\n    # Arrange\n    with Image.open(TEST_FILE) as im:\n        im.info[\"photoshop\"][0x0404] += b\"\\x00\\x00\\x00\"\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n    # Assert\n    assert isinstance(iptc, dict)\n    assert len(iptc) == 3\n\n\ndef test_getiptcinfo_tiff_none():\n    # Arrange\n    with Image.open(\"Tests/images/hopper.tif\") as im:\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n    # Assert\n    assert iptc is None\n\n\ndef test_i():\n    # Arrange\n    c = b\"a\"\n\n    # Act\n    ret = IptcImagePlugin.i(c)\n\n    # Assert\n    assert ret == 97\n\n\ndef test_dump():\n    # Arrange\n    c = b\"abc\"\n    # Temporarily redirect stdout\n    old_stdout = sys.stdout\n    sys.stdout = mystdout = StringIO()\n\n    # Act\n    IptcImagePlugin.dump(c)\n\n    # Reset stdout\n    sys.stdout = old_stdout\n\n    # Assert\n    assert mystdout.getvalue() == \"61 62 63 \\n\"\n",
            "header": {
                "file": {
                    "path": "Tests/test_file_iptc.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "2d99528d3",
                "new_commit_hash": "1e5f2d325",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/Tests/test_file_iptc.py"
            },
            "plus_file": {
                "path": "b/Tests/test_file_iptc.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 30,
                            "length": 6
                        },
                        "new_range": {
                            "start": 30,
                            "length": 19
                        },
                        "section": "def test_getiptcinfo_jpg_found():"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "    assert iptc[(2, 101)] == b\"Hungary\"",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "def test_getiptcinfo_zero_padding():",
                                "type": "added"
                            },
                            {
                                "content": "    # Arrange",
                                "type": "added"
                            },
                            {
                                "content": "    with Image.open(TEST_FILE) as im:",
                                "type": "added"
                            },
                            {
                                "content": "        im.info[\"photoshop\"][0x0404] += b\"\\x00\\x00\\x00\"",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "        # Act",
                                "type": "added"
                            },
                            {
                                "content": "        iptc = IptcImagePlugin.getiptcinfo(im)",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "    # Assert",
                                "type": "added"
                            },
                            {
                                "content": "    assert isinstance(iptc, dict)",
                                "type": "added"
                            },
                            {
                                "content": "    assert len(iptc) == 3",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "def test_getiptcinfo_tiff_none():",
                                "type": "context"
                            },
                            {
                                "content": "    # Arrange",
                                "type": "context"
                            },
                            {
                                "content": "    with Image.open(\"Tests/images/hopper.tif\") as im:",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [],
                    "added_entities": [
                        {
                            "file_name": "Tests/test_file_iptc.py",
                            "type": "function",
                            "name": "test_getiptcinfo_zero_padding",
                            "content": "def test_getiptcinfo_zero_padding():\n    # Arrange\n    with Image.open(TEST_FILE) as im:\n        im.info[\"photoshop\"][0x0404] += b\"\\x00\\x00\\x00\"\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n    # Assert\n    assert isinstance(iptc, dict)\n    assert len(iptc) == 3",
                            "ast_type_str": "FunctionDef",
                            "start_lineno": 33,
                            "end_lineno": 43,
                            "parent": null
                        }
                    ],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# IPTC/NAA file handling\n#\n# history:\n# 1995-10-01 fl   Created\n# 1998-03-09 fl   Cleaned up and added to PIL\n# 2002-06-18 fl   Added getiptcinfo helper\n#\n# Copyright (c) Secret Labs AB 1997-2002.\n# Copyright (c) Fredrik Lundh 1995.\n#\n# See the README file for information on usage and redistribution.\n#\nimport os\nimport tempfile\n\nfrom . import Image, ImageFile\nfrom ._binary import i8\nfrom ._binary import i16be as i16\nfrom ._binary import i32be as i32\nfrom ._binary import o8\n\nCOMPRESSION = {1: \"raw\", 5: \"jpeg\"}\n\nPAD = o8(0) * 4\n\n\n#\n# Helpers\n\n\ndef i(c):\n    return i32((PAD + c)[-4:])\n\n\ndef dump(c):\n    for i in c:\n        print(\"%02x\" % i8(i), end=\" \")\n    print()\n\n\n##\n# Image plugin for IPTC/NAA datastreams.  To read IPTC/NAA fields\n# from TIFF and JPEG files, use the <b>getiptcinfo</b> function.\n\n\nclass IptcImageFile(ImageFile.ImageFile):\n    format = \"IPTC\"\n    format_description = \"IPTC/NAA\"\n\n    def getint(self, key):\n        return i(self.info[key])\n\n    def field(self):\n        #\n        # get a IPTC field header\n        s = self.fp.read(5)\n        if not len(s):\n            return None, 0\n\n        tag = s[1], s[2]\n\n        # syntax\n        if s[0] != 0x1C or tag[0] < 1 or tag[0] > 9:\n            msg = \"invalid IPTC/NAA file\"\n            raise SyntaxError(msg)\n\n        # field size\n        size = s[3]\n        if size > 132:\n            msg = \"illegal field length in IPTC/NAA file\"\n            raise OSError(msg)\n        elif size == 128:\n            size = 0\n        elif size > 128:\n            size = i(self.fp.read(size - 128))\n        else:\n            size = i16(s, 3)\n\n        return tag, size\n\n    def _open(self):\n        # load descriptive fields\n        while True:\n            offset = self.fp.tell()\n            tag, size = self.field()\n            if not tag or tag == (8, 10):\n                break\n            if size:\n                tagdata = self.fp.read(size)\n            else:\n                tagdata = None\n            if tag in self.info:\n                if isinstance(self.info[tag], list):\n                    self.info[tag].append(tagdata)\n                else:\n                    self.info[tag] = [self.info[tag], tagdata]\n            else:\n                self.info[tag] = tagdata\n\n        # mode\n        layers = i8(self.info[(3, 60)][0])\n        component = i8(self.info[(3, 60)][1])\n        if (3, 65) in self.info:\n            id = i8(self.info[(3, 65)][0]) - 1\n        else:\n            id = 0\n        if layers == 1 and not component:\n            self._mode = \"L\"\n        elif layers == 3 and component:\n            self._mode = \"RGB\"[id]\n        elif layers == 4 and component:\n            self._mode = \"CMYK\"[id]\n\n        # size\n        self._size = self.getint((3, 20)), self.getint((3, 30))\n\n        # compression\n        try:\n            compression = COMPRESSION[self.getint((3, 120))]\n        except KeyError as e:\n            msg = \"Unknown IPTC image compression\"\n            raise OSError(msg) from e\n\n        # tile\n        if tag == (8, 10):\n            self.tile = [\n                (\"iptc\", (compression, offset), (0, 0, self.size[0], self.size[1]))\n            ]\n\n    def load(self):\n        if len(self.tile) != 1 or self.tile[0][0] != \"iptc\":\n            return ImageFile.ImageFile.load(self)\n\n        type, tile, box = self.tile[0]\n\n        encoding, offset = tile\n\n        self.fp.seek(offset)\n\n        # Copy image data to temporary file\n        o_fd, outfile = tempfile.mkstemp(text=False)\n        o = os.fdopen(o_fd)\n        if encoding == \"raw\":\n            # To simplify access to the extracted file,\n            # prepend a PPM header\n            o.write(\"P5\\n%d %d\\n255\\n\" % self.size)\n        while True:\n            type, size = self.field()\n            if type != (8, 10):\n                break\n            while size > 0:\n                s = self.fp.read(min(size, 8192))\n                if not s:\n                    break\n                o.write(s)\n                size -= len(s)\n        o.close()\n\n        try:\n            with Image.open(outfile) as _im:\n                _im.load()\n                self.im = _im.im\n        finally:\n            try:\n                os.unlink(outfile)\n            except OSError:\n                pass\n\n\nImage.register_open(IptcImageFile.format, IptcImageFile)\n\nImage.register_extension(IptcImageFile.format, \".iim\")\n\n\ndef getiptcinfo(im):\n    \"\"\"\n    Get IPTC information from TIFF, JPEG, or IPTC file.\n\n    :param im: An image containing IPTC data.\n    :returns: A dictionary containing IPTC information, or None if\n        no IPTC information block was found.\n    \"\"\"\n    import io\n\n    from . import JpegImagePlugin, TiffImagePlugin\n\n    data = None\n\n    if isinstance(im, IptcImageFile):\n        # return info dictionary right away\n        return im.info\n\n    elif isinstance(im, JpegImagePlugin.JpegImageFile):\n        # extract the IPTC/NAA resource\n        photoshop = im.info.get(\"photoshop\")\n        if photoshop:\n            data = photoshop.get(0x0404)\n\n    elif isinstance(im, TiffImagePlugin.TiffImageFile):\n        # get raw data from the IPTC/NAA tag (PhotoShop tags the data\n        # as 4-byte integers, so we cannot use the get method...)\n        try:\n            data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]\n        except (AttributeError, KeyError):\n            pass\n\n    if data is None:\n        return None  # no properties\n\n    # create an IptcImagePlugin object without initializing it\n    class FakeImage:\n        pass\n\n    im = FakeImage()\n    im.__class__ = IptcImageFile\n\n    # parse the IPTC information chunk\n    im.info = {}\n    im.fp = io.BytesIO(data)\n\n    try:\n        im._open()\n    except (IndexError, KeyError):\n        pass  # expected failure\n\n    return im.info\n",
            "new_file_content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# IPTC/NAA file handling\n#\n# history:\n# 1995-10-01 fl   Created\n# 1998-03-09 fl   Cleaned up and added to PIL\n# 2002-06-18 fl   Added getiptcinfo helper\n#\n# Copyright (c) Secret Labs AB 1997-2002.\n# Copyright (c) Fredrik Lundh 1995.\n#\n# See the README file for information on usage and redistribution.\n#\nimport os\nimport tempfile\n\nfrom . import Image, ImageFile\nfrom ._binary import i8\nfrom ._binary import i16be as i16\nfrom ._binary import i32be as i32\nfrom ._binary import o8\n\nCOMPRESSION = {1: \"raw\", 5: \"jpeg\"}\n\nPAD = o8(0) * 4\n\n\n#\n# Helpers\n\n\ndef i(c):\n    return i32((PAD + c)[-4:])\n\n\ndef dump(c):\n    for i in c:\n        print(\"%02x\" % i8(i), end=\" \")\n    print()\n\n\n##\n# Image plugin for IPTC/NAA datastreams.  To read IPTC/NAA fields\n# from TIFF and JPEG files, use the <b>getiptcinfo</b> function.\n\n\nclass IptcImageFile(ImageFile.ImageFile):\n    format = \"IPTC\"\n    format_description = \"IPTC/NAA\"\n\n    def getint(self, key):\n        return i(self.info[key])\n\n    def field(self):\n        #\n        # get a IPTC field header\n        s = self.fp.read(5)\n        if not s.strip(b\"\\x00\"):\n            return None, 0\n\n        tag = s[1], s[2]\n\n        # syntax\n        if s[0] != 0x1C or tag[0] < 1 or tag[0] > 9:\n            msg = \"invalid IPTC/NAA file\"\n            raise SyntaxError(msg)\n\n        # field size\n        size = s[3]\n        if size > 132:\n            msg = \"illegal field length in IPTC/NAA file\"\n            raise OSError(msg)\n        elif size == 128:\n            size = 0\n        elif size > 128:\n            size = i(self.fp.read(size - 128))\n        else:\n            size = i16(s, 3)\n\n        return tag, size\n\n    def _open(self):\n        # load descriptive fields\n        while True:\n            offset = self.fp.tell()\n            tag, size = self.field()\n            if not tag or tag == (8, 10):\n                break\n            if size:\n                tagdata = self.fp.read(size)\n            else:\n                tagdata = None\n            if tag in self.info:\n                if isinstance(self.info[tag], list):\n                    self.info[tag].append(tagdata)\n                else:\n                    self.info[tag] = [self.info[tag], tagdata]\n            else:\n                self.info[tag] = tagdata\n\n        # mode\n        layers = i8(self.info[(3, 60)][0])\n        component = i8(self.info[(3, 60)][1])\n        if (3, 65) in self.info:\n            id = i8(self.info[(3, 65)][0]) - 1\n        else:\n            id = 0\n        if layers == 1 and not component:\n            self._mode = \"L\"\n        elif layers == 3 and component:\n            self._mode = \"RGB\"[id]\n        elif layers == 4 and component:\n            self._mode = \"CMYK\"[id]\n\n        # size\n        self._size = self.getint((3, 20)), self.getint((3, 30))\n\n        # compression\n        try:\n            compression = COMPRESSION[self.getint((3, 120))]\n        except KeyError as e:\n            msg = \"Unknown IPTC image compression\"\n            raise OSError(msg) from e\n\n        # tile\n        if tag == (8, 10):\n            self.tile = [\n                (\"iptc\", (compression, offset), (0, 0, self.size[0], self.size[1]))\n            ]\n\n    def load(self):\n        if len(self.tile) != 1 or self.tile[0][0] != \"iptc\":\n            return ImageFile.ImageFile.load(self)\n\n        type, tile, box = self.tile[0]\n\n        encoding, offset = tile\n\n        self.fp.seek(offset)\n\n        # Copy image data to temporary file\n        o_fd, outfile = tempfile.mkstemp(text=False)\n        o = os.fdopen(o_fd)\n        if encoding == \"raw\":\n            # To simplify access to the extracted file,\n            # prepend a PPM header\n            o.write(\"P5\\n%d %d\\n255\\n\" % self.size)\n        while True:\n            type, size = self.field()\n            if type != (8, 10):\n                break\n            while size > 0:\n                s = self.fp.read(min(size, 8192))\n                if not s:\n                    break\n                o.write(s)\n                size -= len(s)\n        o.close()\n\n        try:\n            with Image.open(outfile) as _im:\n                _im.load()\n                self.im = _im.im\n        finally:\n            try:\n                os.unlink(outfile)\n            except OSError:\n                pass\n\n\nImage.register_open(IptcImageFile.format, IptcImageFile)\n\nImage.register_extension(IptcImageFile.format, \".iim\")\n\n\ndef getiptcinfo(im):\n    \"\"\"\n    Get IPTC information from TIFF, JPEG, or IPTC file.\n\n    :param im: An image containing IPTC data.\n    :returns: A dictionary containing IPTC information, or None if\n        no IPTC information block was found.\n    \"\"\"\n    import io\n\n    from . import JpegImagePlugin, TiffImagePlugin\n\n    data = None\n\n    if isinstance(im, IptcImageFile):\n        # return info dictionary right away\n        return im.info\n\n    elif isinstance(im, JpegImagePlugin.JpegImageFile):\n        # extract the IPTC/NAA resource\n        photoshop = im.info.get(\"photoshop\")\n        if photoshop:\n            data = photoshop.get(0x0404)\n\n    elif isinstance(im, TiffImagePlugin.TiffImageFile):\n        # get raw data from the IPTC/NAA tag (PhotoShop tags the data\n        # as 4-byte integers, so we cannot use the get method...)\n        try:\n            data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]\n        except (AttributeError, KeyError):\n            pass\n\n    if data is None:\n        return None  # no properties\n\n    # create an IptcImagePlugin object without initializing it\n    class FakeImage:\n        pass\n\n    im = FakeImage()\n    im.__class__ = IptcImageFile\n\n    # parse the IPTC information chunk\n    im.info = {}\n    im.fp = io.BytesIO(data)\n\n    try:\n        im._open()\n    except (IndexError, KeyError):\n        pass  # expected failure\n\n    return im.info\n",
            "header": {
                "file": {
                    "path": "src/PIL/IptcImagePlugin.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "6ce4975c0",
                "new_commit_hash": "1616395de",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/src/PIL/IptcImagePlugin.py"
            },
            "plus_file": {
                "path": "b/src/PIL/IptcImagePlugin.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 58,
                            "length": 7
                        },
                        "new_range": {
                            "start": 58,
                            "length": 7
                        },
                        "section": "class IptcImageFile(ImageFile.ImageFile):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        #",
                                "type": "context"
                            },
                            {
                                "content": "        # get a IPTC field header",
                                "type": "context"
                            },
                            {
                                "content": "        s = self.fp.read(5)",
                                "type": "context"
                            },
                            {
                                "content": "        if not len(s):",
                                "type": "deleted"
                            },
                            {
                                "content": "        if not s.strip(b\"\\x00\"):",
                                "type": "added"
                            },
                            {
                                "content": "            return None, 0",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        tag = s[1], s[2]",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "src/PIL/IptcImagePlugin.py",
                            "type": "method",
                            "name": "IptcImageFile.field",
                            "content": "class IptcImageFile(ImageFile.ImageFile):\n    format = \"IPTC\"\n    format_description = \"IPTC/NAA\"\n\n    def getint(self, key):\n        return i(self.info[key])\n\n    def field(self):\n        #\n        # get a IPTC field header\n        s = self.fp.read(5)\n        if not len(s):\n            return None, 0\n\n        tag = s[1], s[2]\n\n        # syntax\n        if s[0] != 0x1C or tag[0] < 1 or tag[0] > 9:\n            msg = \"invalid IPTC/NAA file\"\n            raise SyntaxError(msg)\n\n        # field size\n        size = s[3]\n        if size > 132:\n            msg = \"illegal field length in IPTC/NAA file\"\n            raise OSError(msg)\n        elif size == 128:\n            size = 0\n        elif size > 128:\n            size = i(self.fp.read(size - 128))\n        else:\n            size = i16(s, 3)\n\n        return tag, size\n\n    def _open(self):\n        # load descriptive fields\n        while True:\n            offset = self.fp.tell()\n            tag, size = self.field()\n            if not tag or tag == (8, 10):\n                break\n            if size:\n                tagdata = self.fp.read(size)\n            else:\n                tagdata = None\n            if tag in self.info:\n                if isinstance(self.info[tag], list):\n                    self.info[tag].append(tagdata)\n                else:\n                    self.info[tag] = [self.info[tag], tagdata]\n            else:\n                self.info[tag] = tagdata\n\n        # mode\n        layers = i8(self.info[(3, 60)][0])\n        component = i8(self.info[(3, 60)][1])\n        if (3, 65) in self.info:\n            id = i8(self.info[(3, 65)][0]) - 1\n        else:\n            id = 0\n        if layers == 1 and not component:\n            self._mode = \"L\"\n        elif layers == 3 and component:\n            self._mode = \"RGB\"[id]\n        elif layers == 4 and component:\n            self._mode = \"CMYK\"[id]\n\n        # size\n        self._size = self.getint((3, 20)), self.getint((3, 30))\n\n        # compression\n        try:\n            compression = COMPRESSION[self.getint((3, 120))]\n        except KeyError as e:\n            msg = \"Unknown IPTC image compression\"\n            raise OSError(msg) from e\n\n        # tile\n        if tag == (8, 10):\n            self.tile = [\n                (\"iptc\", (compression, offset), (0, 0, self.size[0], self.size[1]))\n            ]\n\n    def load(self):\n        if len(self.tile) != 1 or self.tile[0][0] != \"iptc\":\n            return ImageFile.ImageFile.load(self)\n\n        type, tile, box = self.tile[0]\n\n        encoding, offset = tile\n\n        self.fp.seek(offset)\n\n        # Copy image data to temporary file\n        o_fd, outfile = tempfile.mkstemp(text=False)\n        o = os.fdopen(o_fd)\n        if encoding == \"raw\":\n            # To simplify access to the extracted file,\n            # prepend a PPM header\n            o.write(\"P5\\n%d %d\\n255\\n\" % self.size)\n        while True:\n            type, size = self.field()\n            if type != (8, 10):\n                break\n            while size > 0:\n                s = self.fp.read(min(size, 8192))\n                if not s:\n                    break\n                o.write(s)\n                size -= len(s)\n        o.close()\n\n        try:\n            with Image.open(outfile) as _im:\n                _im.load()\n                self.im = _im.im\n        finally:\n            try:\n                os.unlink(outfile)\n            except OSError:\n                pass",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 57,
                            "end_lineno": 83,
                            "parent": {
                                "file_name": "src/PIL/IptcImagePlugin.py",
                                "type": "class",
                                "name": "IptcImageFile",
                                "content": "class IptcImageFile(ImageFile.ImageFile):\n    format = \"IPTC\"\n    format_description = \"IPTC/NAA\"\n\n    def getint(self, key):\n        return i(self.info[key])\n\n    def field(self):\n        #\n        # get a IPTC field header\n        s = self.fp.read(5)\n        if not len(s):\n            return None, 0\n\n        tag = s[1], s[2]\n\n        # syntax\n        if s[0] != 0x1C or tag[0] < 1 or tag[0] > 9:\n            msg = \"invalid IPTC/NAA file\"\n            raise SyntaxError(msg)\n\n        # field size\n        size = s[3]\n        if size > 132:\n            msg = \"illegal field length in IPTC/NAA file\"\n            raise OSError(msg)\n        elif size == 128:\n            size = 0\n        elif size > 128:\n            size = i(self.fp.read(size - 128))\n        else:\n            size = i16(s, 3)\n\n        return tag, size\n\n    def _open(self):\n        # load descriptive fields\n        while True:\n            offset = self.fp.tell()\n            tag, size = self.field()\n            if not tag or tag == (8, 10):\n                break\n            if size:\n                tagdata = self.fp.read(size)\n            else:\n                tagdata = None\n            if tag in self.info:\n                if isinstance(self.info[tag], list):\n                    self.info[tag].append(tagdata)\n                else:\n                    self.info[tag] = [self.info[tag], tagdata]\n            else:\n                self.info[tag] = tagdata\n\n        # mode\n        layers = i8(self.info[(3, 60)][0])\n        component = i8(self.info[(3, 60)][1])\n        if (3, 65) in self.info:\n            id = i8(self.info[(3, 65)][0]) - 1\n        else:\n            id = 0\n        if layers == 1 and not component:\n            self._mode = \"L\"\n        elif layers == 3 and component:\n            self._mode = \"RGB\"[id]\n        elif layers == 4 and component:\n            self._mode = \"CMYK\"[id]\n\n        # size\n        self._size = self.getint((3, 20)), self.getint((3, 30))\n\n        # compression\n        try:\n            compression = COMPRESSION[self.getint((3, 120))]\n        except KeyError as e:\n            msg = \"Unknown IPTC image compression\"\n            raise OSError(msg) from e\n\n        # tile\n        if tag == (8, 10):\n            self.tile = [\n                (\"iptc\", (compression, offset), (0, 0, self.size[0], self.size[1]))\n            ]\n\n    def load(self):\n        if len(self.tile) != 1 or self.tile[0][0] != \"iptc\":\n            return ImageFile.ImageFile.load(self)\n\n        type, tile, box = self.tile[0]\n\n        encoding, offset = tile\n\n        self.fp.seek(offset)\n\n        # Copy image data to temporary file\n        o_fd, outfile = tempfile.mkstemp(text=False)\n        o = os.fdopen(o_fd)\n        if encoding == \"raw\":\n            # To simplify access to the extracted file,\n            # prepend a PPM header\n            o.write(\"P5\\n%d %d\\n255\\n\" % self.size)\n        while True:\n            type, size = self.field()\n            if type != (8, 10):\n                break\n            while size > 0:\n                s = self.fp.read(min(size, 8192))\n                if not s:\n                    break\n                o.write(s)\n                size -= len(s)\n        o.close()\n\n        try:\n            with Image.open(outfile) as _im:\n                _im.load()\n                self.im = _im.im\n        finally:\n            try:\n                os.unlink(outfile)\n            except OSError:\n                pass",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 50,
                                "end_lineno": 171,
                                "parent": null
                            }
                        },
                        {
                            "file_name": "src/PIL/IptcImagePlugin.py",
                            "type": "class",
                            "name": "IptcImageFile",
                            "content": "class IptcImageFile(ImageFile.ImageFile):\n    format = \"IPTC\"\n    format_description = \"IPTC/NAA\"\n\n    def getint(self, key):\n        return i(self.info[key])\n\n    def field(self):\n        #\n        # get a IPTC field header\n        s = self.fp.read(5)\n        if not len(s):\n            return None, 0\n\n        tag = s[1], s[2]\n\n        # syntax\n        if s[0] != 0x1C or tag[0] < 1 or tag[0] > 9:\n            msg = \"invalid IPTC/NAA file\"\n            raise SyntaxError(msg)\n\n        # field size\n        size = s[3]\n        if size > 132:\n            msg = \"illegal field length in IPTC/NAA file\"\n            raise OSError(msg)\n        elif size == 128:\n            size = 0\n        elif size > 128:\n            size = i(self.fp.read(size - 128))\n        else:\n            size = i16(s, 3)\n\n        return tag, size\n\n    def _open(self):\n        # load descriptive fields\n        while True:\n            offset = self.fp.tell()\n            tag, size = self.field()\n            if not tag or tag == (8, 10):\n                break\n            if size:\n                tagdata = self.fp.read(size)\n            else:\n                tagdata = None\n            if tag in self.info:\n                if isinstance(self.info[tag], list):\n                    self.info[tag].append(tagdata)\n                else:\n                    self.info[tag] = [self.info[tag], tagdata]\n            else:\n                self.info[tag] = tagdata\n\n        # mode\n        layers = i8(self.info[(3, 60)][0])\n        component = i8(self.info[(3, 60)][1])\n        if (3, 65) in self.info:\n            id = i8(self.info[(3, 65)][0]) - 1\n        else:\n            id = 0\n        if layers == 1 and not component:\n            self._mode = \"L\"\n        elif layers == 3 and component:\n            self._mode = \"RGB\"[id]\n        elif layers == 4 and component:\n            self._mode = \"CMYK\"[id]\n\n        # size\n        self._size = self.getint((3, 20)), self.getint((3, 30))\n\n        # compression\n        try:\n            compression = COMPRESSION[self.getint((3, 120))]\n        except KeyError as e:\n            msg = \"Unknown IPTC image compression\"\n            raise OSError(msg) from e\n\n        # tile\n        if tag == (8, 10):\n            self.tile = [\n                (\"iptc\", (compression, offset), (0, 0, self.size[0], self.size[1]))\n            ]\n\n    def load(self):\n        if len(self.tile) != 1 or self.tile[0][0] != \"iptc\":\n            return ImageFile.ImageFile.load(self)\n\n        type, tile, box = self.tile[0]\n\n        encoding, offset = tile\n\n        self.fp.seek(offset)\n\n        # Copy image data to temporary file\n        o_fd, outfile = tempfile.mkstemp(text=False)\n        o = os.fdopen(o_fd)\n        if encoding == \"raw\":\n            # To simplify access to the extracted file,\n            # prepend a PPM header\n            o.write(\"P5\\n%d %d\\n255\\n\" % self.size)\n        while True:\n            type, size = self.field()\n            if type != (8, 10):\n                break\n            while size > 0:\n                s = self.fp.read(min(size, 8192))\n                if not s:\n                    break\n                o.write(s)\n                size -= len(s)\n        o.close()\n\n        try:\n            with Image.open(outfile) as _im:\n                _im.load()\n                self.im = _im.im\n        finally:\n            try:\n                os.unlink(outfile)\n            except OSError:\n                pass",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 50,
                            "end_lineno": 171,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        }
    ],
    "old_commit_hash": "6bd3ed439a2f7f542df52c39211ae37a48b75238^",
    "new_commit_hash": "6bd3ed439a2f7f542df52c39211ae37a48b75238",
    "commit_message": "Ignore IPTC field that is only zero bytes",
    "commit_date": "2023-08-04T23:54:48+10:00",
    "metadata": {}
}
{
    "repo_name": "pillow",
    "new_commit_hash": "6bd3ed439a2f7f542df52c39211ae37a48b75238",
    "test_file_codes": [
        "import sys\nfrom io import StringIO\n\nfrom PIL import Image, IptcImagePlugin\n\nfrom .helper import hopper\n\nTEST_FILE = \"Tests/images/iptc.jpg\"\n\n\ndef test_getiptcinfo_jpg_none():\n    # Arrange\n    with hopper() as im:\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n    # Assert\n    assert iptc is None\n\n\ndef test_getiptcinfo_jpg_found():\n    # Arrange\n    with Image.open(TEST_FILE) as im:\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n    # Assert\n    assert isinstance(iptc, dict)\n    assert iptc[(2, 90)] == b\"Budapest\"\n    assert iptc[(2, 101)] == b\"Hungary\"\n\n\ndef test_getiptcinfo_zero_padding():\n    # Arrange\n    with Image.open(TEST_FILE) as im:\n        im.info[\"photoshop\"][0x0404] += b\"\\x00\\x00\\x00\"\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n    # Assert\n    assert isinstance(iptc, dict)\n    assert len(iptc) == 3\n\n\ndef test_getiptcinfo_tiff_none():\n    # Arrange\n    with Image.open(\"Tests/images/hopper.tif\") as im:\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n    # Assert\n    assert iptc is None\n\n\ndef test_i():\n    # Arrange\n    c = b\"a\"\n\n    # Act\n    ret = IptcImagePlugin.i(c)\n\n    # Assert\n    assert ret == 97\n\n\ndef test_dump():\n    # Arrange\n    c = b\"abc\"\n    # Temporarily redirect stdout\n    old_stdout = sys.stdout\n    sys.stdout = mystdout = StringIO()\n\n    # Act\n    IptcImagePlugin.dump(c)\n\n    # Reset stdout\n    sys.stdout = old_stdout\n\n    # Assert\n    assert mystdout.getvalue() == \"61 62 63 \\n\"\n"
    ],
    "test_file_names": [
        "test_1.py"
    ],
    "setup_res_code": 0,
    "setup_res_stdout": "Starting Pillow installation attempts...\nVerifying Pillow installation...\n✅ Pillow installation successful!\nSuccessfully installed Pillow\n",
    "setup_res_stderr": "Using CPython 3.9.21\nCreating virtual environment at: .venv\nActivate with: source .venv/bin/activate\nResolved 12 packages in 24ms\nInstalled 12 packages in 187ms\n + coverage==7.6.10\n + exceptiongroup==1.2.2\n + iniconfig==2.0.0\n + packaging==24.2\n + pluggy==1.5.0\n + pyqt5==5.15.11\n + pyqt5-qt5==5.15.16\n + pyqt5-sip==12.16.1\n + pytest==8.3.4\n + pytest-cov==6.0.0\n + setuptools==75.8.0\n + tomli==2.2.1\nResolved 1 package in 824ms\nPrepared 1 package in 32.68s\nInstalled 1 package in 1ms\n + pillow==10.1.0.dev0 (from file:///home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_6bd3ed439a2f7f542df52c39211ae37a48b75238)\n",
    "new_commit_res_code": 0,
    "new_commit_res_stdout": "\u001b[1m============================= test session starts ==============================\u001b[0m\nplatform linux -- Python 3.9.21, pytest-8.3.4, pluggy-1.5.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_6bd3ed439a2f7f542df52c39211ae37a48b75238\nconfigfile: setup.cfg\nplugins: cov-6.0.0\ncollected 6 items\n\nr2e_tests/test_1.py \u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m                                               [100%]\u001b[0m\n\n==================================== PASSES ====================================\n\u001b[36m\u001b[1m=========================== short test summary info ============================\u001b[0m\n\u001b[32mPASSED\u001b[0m r2e_tests/test_1.py::\u001b[1mtest_getiptcinfo_jpg_none\u001b[0m\n\u001b[32mPASSED\u001b[0m r2e_tests/test_1.py::\u001b[1mtest_getiptcinfo_jpg_found\u001b[0m\n\u001b[32mPASSED\u001b[0m r2e_tests/test_1.py::\u001b[1mtest_getiptcinfo_zero_padding\u001b[0m\n\u001b[32mPASSED\u001b[0m r2e_tests/test_1.py::\u001b[1mtest_getiptcinfo_tiff_none\u001b[0m\n\u001b[32mPASSED\u001b[0m r2e_tests/test_1.py::\u001b[1mtest_i\u001b[0m\n\u001b[32mPASSED\u001b[0m r2e_tests/test_1.py::\u001b[1mtest_dump\u001b[0m\n\u001b[32m============================== \u001b[32m\u001b[1m6 passed\u001b[0m\u001b[32m in 0.11s\u001b[0m\u001b[32m ===============================\u001b[0m\n",
    "new_commit_res_stderr": "",
    "old_commit_res_code": 1,
    "old_commit_res_stdout": "\u001b[1m============================= test session starts ==============================\u001b[0m\nplatform linux -- Python 3.9.21, pytest-8.3.4, pluggy-1.5.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_6bd3ed439a2f7f542df52c39211ae37a48b75238\nconfigfile: setup.cfg\nplugins: cov-6.0.0\ncollected 6 items\n\nr2e_tests/test_1.py \u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[31mF\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[31m                                               [100%]\u001b[0m\n\n=================================== FAILURES ===================================\n\u001b[31m\u001b[1m________________________ test_getiptcinfo_zero_padding _________________________\u001b[0m\n\n    def test_getiptcinfo_zero_padding():\n        # Arrange\n        with Image.open(TEST_FILE) as im:\n            im.info[\"photoshop\"][0x0404] += b\"\\x00\\x00\\x00\"\n    \n            # Act\n>           iptc = IptcImagePlugin.getiptcinfo(im)\n\n\u001b[1m\u001b[31mr2e_tests/test_1.py\u001b[0m:39: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\u001b[1m\u001b[31msrc/PIL/IptcImagePlugin.py\u001b[0m:226: in getiptcinfo\n    im._open()\n\u001b[1m\u001b[31msrc/PIL/IptcImagePlugin.py\u001b[0m:89: in _open\n    tag, size = self.field()\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <[AttributeError(\"'IptcImageFile' object has no attribute '_mode'\") raised in repr()] IptcImageFile object at 0x7f5d44f3c6d0>\n\n    def field(self):\n        #\n        # get a IPTC field header\n        s = self.fp.read(5)\n        if not len(s):\n            return None, 0\n    \n        tag = s[1], s[2]\n    \n        # syntax\n        if s[0] != 0x1C or tag[0] < 1 or tag[0] > 9:\n            msg = \"invalid IPTC/NAA file\"\n>           raise SyntaxError(msg)\n\u001b[1m\u001b[31mE           SyntaxError: invalid IPTC/NAA file\u001b[0m\n\n\u001b[1m\u001b[31msrc/PIL/IptcImagePlugin.py\u001b[0m:69: SyntaxError\n==================================== PASSES ====================================\n\u001b[36m\u001b[1m=========================== short test summary info ============================\u001b[0m\n\u001b[32mPASSED\u001b[0m r2e_tests/test_1.py::\u001b[1mtest_getiptcinfo_jpg_none\u001b[0m\n\u001b[32mPASSED\u001b[0m r2e_tests/test_1.py::\u001b[1mtest_getiptcinfo_jpg_found\u001b[0m\n\u001b[32mPASSED\u001b[0m r2e_tests/test_1.py::\u001b[1mtest_getiptcinfo_tiff_none\u001b[0m\n\u001b[32mPASSED\u001b[0m r2e_tests/test_1.py::\u001b[1mtest_i\u001b[0m\n\u001b[32mPASSED\u001b[0m r2e_tests/test_1.py::\u001b[1mtest_dump\u001b[0m\n\u001b[31mFAILED\u001b[0m r2e_tests/test_1.py::\u001b[1mtest_getiptcinfo_zero_padding\u001b[0m - SyntaxError: invalid IPTC/NAA file\n\u001b[31m========================= \u001b[31m\u001b[1m1 failed\u001b[0m, \u001b[32m5 passed\u001b[0m\u001b[31m in 0.08s\u001b[0m\u001b[31m ==========================\u001b[0m\n",
    "old_commit_res_stderr": ""
}
Tests/test_file_iptc.py src/PIL/IptcImagePlugin.py
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** IPTC Fields Containing Only Zero Bytes Raise SyntaxError

**Description:**
When processing an image with IPTC data that includes fields consisting solely of zero bytes, the library incorrectly raises a `SyntaxError` indicating an invalid IPTC/NAA file. These zero-byte IPTC fields should be ignored to allow proper extraction of IPTC information.

**Example Code:**
```python
from PIL import Image, IptcImagePlugin

with Image.open(TEST_FILE) as im:
    im.info["photoshop"][0x0404] += b"\x00\x00\x00"
    iptc = IptcImagePlugin.getiptcinfo(im)
```

**Expected Behavior:**
IPTC fields containing only zero bytes are ignored, and the `iptc` dictionary contains the valid IPTC information without raising any errors.

**Actual Behavior:**
A `SyntaxError` is raised with the message "invalid IPTC/NAA file" when encountering IPTC fields that consist solely of zero bytes.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### src/PIL/IptcImagePlugin.py
#
# The Python Imaging Library.
# $Id$
#
# IPTC/NAA file handling
#
# history:
# 1995-10-01 fl   Created
# 1998-03-09 fl   Cleaned up and added to PIL
# 2002-06-18 fl   Added getiptcinfo helper
#
# Copyright (c) Secret Labs AB 1997-2002.
# Copyright (c) Fredrik Lundh 1995.
#
# See the README file for information on usage and redistribution.
#
import os
import tempfile

from . import Image, ImageFile
from ._binary import i8
from ._binary import i16be as i16
from ._binary import i32be as i32
from ._binary import o8

COMPRESSION = {1: "raw", 5: "jpeg"}

PAD = o8(0) * 4


#
# Helpers


def i(c):
    return i32((PAD + c)[-4:])


def dump(c):
    for i in c:
        print("%02x" % i8(i), end=" ")
    print()


##
# Image plugin for IPTC/NAA datastreams.  To read IPTC/NAA fields
# from TIFF and JPEG files, use the <b>getiptcinfo</b> function.


class IptcImageFile(ImageFile.ImageFile):
    format = "IPTC"
    format_description = "IPTC/NAA"

    def getint(self, key):
        return i(self.info[key])

    def field(self):
        #
        # get a IPTC field header
        s = self.fp.read(5)
        if not len(s):
            return None, 0

        tag = s[1], s[2]

        # syntax
        if s[0] != 0x1C or tag[0] < 1 or tag[0] > 9:
            msg = "invalid IPTC/NAA file"
            raise SyntaxError(msg)

        # field size
        size = s[3]
        if size > 132:
            msg = "illegal field length in IPTC/NAA file"
            raise OSError(msg)
        elif size == 128:
            size = 0
        elif size > 128:
            size = i(self.fp.read(size - 128))
        else:
            size = i16(s, 3)

        return tag, size

    def _open(self):
        # load descriptive fields
        while True:
            offset = self.fp.tell()
            tag, size = self.field()
            if not tag or tag == (8, 10):
                break
            if size:
                tagdata = self.fp.read(size)
            else:
                tagdata = None
            if tag in self.info:
                if isinstance(self.info[tag], list):
                    self.info[tag].append(tagdata)
                else:
                    self.info[tag] = [self.info[tag], tagdata]
            else:
                self.info[tag] = tagdata

        # mode
        layers = i8(self.info[(3, 60)][0])
        component = i8(self.info[(3, 60)][1])
        if (3, 65) in self.info:
            id = i8(self.info[(3, 65)][0]) - 1
        else:
            id = 0
        if layers == 1 and not component:
            self._mode = "L"
        elif layers == 3 and component:
            self._mode = "RGB"[id]
        elif layers == 4 and component:
            self._mode = "CMYK"[id]

        # size
        self._size = self.getint((3, 20)), self.getint((3, 30))

        # compression
        try:
            compression = COMPRESSION[self.getint((3, 120))]
        except KeyError as e:
            msg = "Unknown IPTC image compression"
            raise OSError(msg) from e

        # tile
        if tag == (8, 10):
            self.tile = [
                ("iptc", (compression, offset), (0, 0, self.size[0], self.size[1]))
            ]

    def load(self):
        if len(self.tile) != 1 or self.tile[0][0] != "iptc":
            return ImageFile.ImageFile.load(self)

        type, tile, box = self.tile[0]

        encoding, offset = tile

        self.fp.seek(offset)

        # Copy image data to temporary file
        o_fd, outfile = tempfile.mkstemp(text=False)
        o = os.fdopen(o_fd)
        if encoding == "raw":
            # To simplify access to the extracted file,
            # prepend a PPM header
            o.write("P5\n%d %d\n255\n" % self.size)
        while True:
            type, size = self.field()
            if type != (8, 10):
                break
            while size > 0:
                s = self.fp.read(min(size, 8192))
                if not s:
                    break
                o.write(s)
                size -= len(s)
        o.close()

        try:
            with Image.open(outfile) as _im:
                _im.load()
                self.im = _im.im
        finally:
            try:
                os.unlink(outfile)
            except OSError:
                pass


Image.register_open(IptcImageFile.format, IptcImageFile)

Image.register_extension(IptcImageFile.format, ".iim")


def getiptcinfo(im):
    """
    Get IPTC information from TIFF, JPEG, or IPTC file.

    :param im: An image containing IPTC data.
    :returns: A dictionary containing IPTC information, or None if
        no IPTC information block was found.
    """
    import io

    from . import JpegImagePlugin, TiffImagePlugin

    data = None

    if isinstance(im, IptcImageFile):
        # return info dictionary right away
        return im.info

    elif isinstance(im, JpegImagePlugin.JpegImageFile):
        # extract the IPTC/NAA resource
        photoshop = im.info.get("photoshop")
        if photoshop:
            data = photoshop.get(0x0404)

    elif isinstance(im, TiffImagePlugin.TiffImageFile):
        # get raw data from the IPTC/NAA tag (PhotoShop tags the data
        # as 4-byte integers, so we cannot use the get method...)
        try:
            data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]
        except (AttributeError, KeyError):
            pass

    if data is None:
        return None  # no properties

    # create an IptcImagePlugin object without initializing it
    class FakeImage:
        pass

    im = FakeImage()
    im.__class__ = IptcImageFile

    # parse the IPTC information chunk
    im.info = {}
    im.fp = io.BytesIO(data)

    try:
        im._open()
    except (IndexError, KeyError):
        pass  # expected failure

    return im.info

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
[ISSUE]
**Title:** IPTC Fields Containing Only Zero Bytes Raise SyntaxError

**Description:**
When processing an image with IPTC data that includes fields consisting solely of zero bytes, the library incorrectly raises a `SyntaxError` indicating an invalid IPTC/NAA file. These zero-byte IPTC fields should be ignored to allow proper extraction of IPTC information.

**Example Code:**
```python
from PIL import Image, IptcImagePlugin

with Image.open(TEST_FILE) as im:
    im.info["photoshop"][0x0404] += b"\x00\x00\x00"
    iptc = IptcImagePlugin.getiptcinfo(im)
```

**Expected Behavior:**
IPTC fields containing only zero bytes are ignored, and the `iptc` dictionary contains the valid IPTC information without raising any errors.

**Actual Behavior:**
A `SyntaxError` is raised with the message "invalid IPTC/NAA file" when encountering IPTC fields that consist solely of zero bytes.

[/ISSUE]
{
    "\u001b[1mtest_getiptcinfo_jpg_none\u001b[0m": "PASSED",
    "\u001b[1mtest_getiptcinfo_jpg_found\u001b[0m": "PASSED",
    "\u001b[1mtest_getiptcinfo_zero_padding\u001b[0m": "PASSED",
    "\u001b[1mtest_getiptcinfo_tiff_none\u001b[0m": "PASSED",
    "\u001b[1mtest_i\u001b[0m": "PASSED",
    "\u001b[1mtest_dump\u001b[0m": "PASSED"
}
diff --git a/src/PIL/IptcImagePlugin.py b/src/PIL/IptcImagePlugin.py
index 6ce4975c0..1616395de 100644
--- a/src/PIL/IptcImagePlugin.py
+++ b/src/PIL/IptcImagePlugin.py
@@ -58,7 +58,7 @@ class IptcImageFile(ImageFile.ImageFile):
         #
         # get a IPTC field header
         s = self.fp.read(5)
-        if not len(s):
+        if not s.strip(b"\x00"):
             return None, 0
 
         tag = s[1], s[2]
 

{"src/PIL/IptcImagePlugin.py": "#\n# The Python Imaging Library.\n# $Id$\n#\n# IPTC/NAA file handling\n#\n# history:\n# 1995-10-01 fl   Created\n# 1998-03-09 fl   Cleaned up and added to PIL\n# 2002-06-18 fl   Added getiptcinfo helper\n#\n# Copyright (c) Secret Labs AB 1997-2002.\n# Copyright (c) Fredrik Lundh 1995.\n#\n# See the README file for information on usage and redistribution.\n#\nimport os\nimport tempfile\n\nfrom . import Image, ImageFile\nfrom ._binary import i8\nfrom ._binary import i16be as i16\nfrom ._binary import i32be as i32\nfrom ._binary import o8\n\nCOMPRESSION = {1: \"raw\", 5: \"jpeg\"}\n\nPAD = o8(0) * 4\n\n\n#\n# Helpers\n\n\ndef i(c):\n    return i32((PAD + c)[-4:])\n\n\ndef dump(c):\n    for i in c:\n        print(\"%02x\" % i8(i), end=\" \")\n    print()\n\n\n##\n# Image plugin for IPTC/NAA datastreams.  To read IPTC/NAA fields\n# from TIFF and JPEG files, use the <b>getiptcinfo</b> function.\n\n\nclass IptcImageFile(ImageFile.ImageFile):\n    format = \"IPTC\"\n    format_description = \"IPTC/NAA\"\n\n    def getint(self, key):\n        return i(self.info[key])\n\n    def field(self):\n        #\n        # get a IPTC field header\n        s = self.fp.read(5)\n        if not len(s):\n            return None, 0\n\n        tag = s[1], s[2]\n\n        # syntax\n        if s[0] != 0x1C or tag[0] < 1 or tag[0] > 9:\n            msg = \"invalid IPTC/NAA file\"\n            raise SyntaxError(msg)\n\n        # field size\n        size = s[3]\n        if size > 132:\n            msg = \"illegal field length in IPTC/NAA file\"\n            raise OSError(msg)\n        elif size == 128:\n            size = 0\n        elif size > 128:\n            size = i(self.fp.read(size - 128))\n        else:\n            size = i16(s, 3)\n\n        return tag, size\n\n    def _open(self):\n        # load descriptive fields\n        while True:\n            offset = self.fp.tell()\n            tag, size = self.field()\n            if not tag or tag == (8, 10):\n                break\n            if size:\n                tagdata = self.fp.read(size)\n            else:\n                tagdata = None\n            if tag in self.info:\n                if isinstance(self.info[tag], list):\n                    self.info[tag].append(tagdata)\n                else:\n                    self.info[tag] = [self.info[tag], tagdata]\n            else:\n                self.info[tag] = tagdata\n\n        # mode\n        layers = i8(self.info[(3, 60)][0])\n        component = i8(self.info[(3, 60)][1])\n        if (3, 65) in self.info:\n            id = i8(self.info[(3, 65)][0]) - 1\n        else:\n            id = 0\n        if layers == 1 and not component:\n            self._mode = \"L\"\n        elif layers == 3 and component:\n            self._mode = \"RGB\"[id]\n        elif layers == 4 and component:\n            self._mode = \"CMYK\"[id]\n\n        # size\n        self._size = self.getint((3, 20)), self.getint((3, 30))\n\n        # compression\n        try:\n            compression = COMPRESSION[self.getint((3, 120))]\n        except KeyError as e:\n            msg = \"Unknown IPTC image compression\"\n            raise OSError(msg) from e\n\n        # tile\n        if tag == (8, 10):\n            self.tile = [\n                (\"iptc\", (compression, offset), (0, 0, self.size[0], self.size[1]))\n            ]\n\n    def load(self):\n        if len(self.tile) != 1 or self.tile[0][0] != \"iptc\":\n            return ImageFile.ImageFile.load(self)\n\n        type, tile, box = self.tile[0]\n\n        encoding, offset = tile\n\n        self.fp.seek(offset)\n\n        # Copy image data to temporary file\n        o_fd, outfile = tempfile.mkstemp(text=False)\n        o = os.fdopen(o_fd)\n        if encoding == \"raw\":\n            # To simplify access to the extracted file,\n            # prepend a PPM header\n            o.write(\"P5\\n%d %d\\n255\\n\" % self.size)\n        while True:\n            type, size = self.field()\n            if type != (8, 10):\n                break\n            while size > 0:\n                s = self.fp.read(min(size, 8192))\n                if not s:\n                    break\n                o.write(s)\n                size -= len(s)\n        o.close()\n\n        try:\n            with Image.open(outfile) as _im:\n                _im.load()\n                self.im = _im.im\n        finally:\n            try:\n                os.unlink(outfile)\n            except OSError:\n                pass\n\n\nImage.register_open(IptcImageFile.format, IptcImageFile)\n\nImage.register_extension(IptcImageFile.format, \".iim\")\n\n\ndef getiptcinfo(im):\n    \"\"\"\n    Get IPTC information from TIFF, JPEG, or IPTC file.\n\n    :param im: An image containing IPTC data.\n    :returns: A dictionary containing IPTC information, or None if\n        no IPTC information block was found.\n    \"\"\"\n    import io\n\n    from . import JpegImagePlugin, TiffImagePlugin\n\n    data = None\n\n    if isinstance(im, IptcImageFile):\n        # return info dictionary right away\n        return im.info\n\n    elif isinstance(im, JpegImagePlugin.JpegImageFile):\n        # extract the IPTC/NAA resource\n        photoshop = im.info.get(\"photoshop\")\n        if photoshop:\n            data = photoshop.get(0x0404)\n\n    elif isinstance(im, TiffImagePlugin.TiffImageFile):\n        # get raw data from the IPTC/NAA tag (PhotoShop tags the data\n        # as 4-byte integers, so we cannot use the get method...)\n        try:\n            data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]\n        except (AttributeError, KeyError):\n            pass\n\n    if data is None:\n        return None  # no properties\n\n    # create an IptcImagePlugin object without initializing it\n    class FakeImage:\n        pass\n\n    im = FakeImage()\n    im.__class__ = IptcImageFile\n\n    # parse the IPTC information chunk\n    im.info = {}\n    im.fp = io.BytesIO(data)\n\n    try:\n        im._open()\n    except (IndexError, KeyError):\n        pass  # expected failure\n\n    return im.info\n"}
A user will ask you to solve a task. You should first draft your thinking process (inner monologue). Then, generate the solution.

Your response format must follow the template below:
<think>
Your thoughts or/and draft, like working through an exercise on scratch paper. Be as casual and as long as you want until you are confident to generate a correct solution.
</think>
<solution>
Final solution presented to the user.
</solution>
system
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** IPTC Fields Containing Only Zero Bytes Raise SyntaxError

**Description:**
When processing an image with IPTC data that includes fields consisting solely of zero bytes, the library incorrectly raises a `SyntaxError` indicating an invalid IPTC/NAA file. These zero-byte IPTC fields should be ignored to allow proper extraction of IPTC information.

**Example Code:**
```python
from PIL import Image, IptcImagePlugin

with Image.open(TEST_FILE) as im:
    im.info["photoshop"][0x0404] += b"\x00\x00\x00"
    iptc = IptcImagePlugin.getiptcinfo(im)
```

**Expected Behavior:**
IPTC fields containing only zero bytes are ignored, and the `iptc` dictionary contains the valid IPTC information without raising any errors.

**Actual Behavior:**
A `SyntaxError` is raised with the message "invalid IPTC/NAA file" when encountering IPTC fields that consist solely of zero bytes.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### src/PIL/IptcImagePlugin.py
#
# The Python Imaging Library.
# $Id$
#
# IPTC/NAA file handling
#
# history:
# 1995-10-01 fl   Created
# 1998-03-09 fl   Cleaned up and added to PIL
# 2002-06-18 fl   Added getiptcinfo helper
#
# Copyright (c) Secret Labs AB 1997-2002.
# Copyright (c) Fredrik Lundh 1995.
#
# See the README file for information on usage and redistribution.
#
import os
import tempfile

from . import Image, ImageFile
from ._binary import i8
from ._binary import i16be as i16
from ._binary import i32be as i32
from ._binary import o8

COMPRESSION = {1: "raw", 5: "jpeg"}

PAD = o8(0) * 4


#
# Helpers


def i(c):
    return i32((PAD + c)[-4:])


def dump(c):
    for i in c:
        print("%02x" % i8(i), end=" ")
    print()


##
# Image plugin for IPTC/NAA datastreams.  To read IPTC/NAA fields
# from TIFF and JPEG files, use the <b>getiptcinfo</b> function.


class IptcImageFile(ImageFile.ImageFile):
    format = "IPTC"
    format_description = "IPTC/NAA"

    def getint(self, key):
        return i(self.info[key])

    def field(self):
        #
        # get a IPTC field header
        s = self.fp.read(5)
        if not len(s):
            return None, 0

        tag = s[1], s[2]

        # syntax
        if s[0] != 0x1C or tag[0] < 1 or tag[0] > 9:
            msg = "invalid IPTC/NAA file"
            raise SyntaxError(msg)

        # field size
        size = s[3]
        if size > 132:
            msg = "illegal field length in IPTC/NAA file"
            raise OSError(msg)
        elif size == 128:
            size = 0
        elif size > 128:
            size = i(self.fp.read(size - 128))
        else:
            size = i16(s, 3)

        return tag, size

    def _open(self):
        # load descriptive fields
        while True:
            offset = self.fp.tell()
            tag, size = self.field()
            if not tag or tag == (8, 10):
                break
            if size:
                tagdata = self.fp.read(size)
            else:
                tagdata = None
            if tag in self.info:
                if isinstance(self.info[tag], list):
                    self.info[tag].append(tagdata)
                else:
                    self.info[tag] = [self.info[tag], tagdata]
            else:
                self.info[tag] = tagdata

        # mode
        layers = i8(self.info[(3, 60)][0])
        component = i8(self.info[(3, 60)][1])
        if (3, 65) in self.info:
            id = i8(self.info[(3, 65)][0]) - 1
        else:
            id = 0
        if layers == 1 and not component:
            self._mode = "L"
        elif layers == 3 and component:
            self._mode = "RGB"[id]
        elif layers == 4 and component:
            self._mode = "CMYK"[id]

        # size
        self._size = self.getint((3, 20)), self.getint((3, 30))

        # compression
        try:
            compression = COMPRESSION[self.getint((3, 120))]
        except KeyError as e:
            msg = "Unknown IPTC image compression"
            raise OSError(msg) from e

        # tile
        if tag == (8, 10):
            self.tile = [
                ("iptc", (compression, offset), (0, 0, self.size[0], self.size[1]))
            ]

    def load(self):
        if len(self.tile) != 1 or self.tile[0][0] != "iptc":
            return ImageFile.ImageFile.load(self)

        type, tile, box = self.tile[0]

        encoding, offset = tile

        self.fp.seek(offset)

        # Copy image data to temporary file
        o_fd, outfile = tempfile.mkstemp(text=False)
        o = os.fdopen(o_fd)
        if encoding == "raw":
            # To simplify access to the extracted file,
            # prepend a PPM header
            o.write("P5\n%d %d\n255\n" % self.size)
        while True:
            type, size = self.field()
            if type != (8, 10):
                break
            while size > 0:
                s = self.fp.read(min(size, 8192))
                if not s:
                    break
                o.write(s)
                size -= len(s)
        o.close()

        try:
            with Image.open(outfile) as _im:
                _im.load()
                self.im = _im.im
        finally:
            try:
                os.unlink(outfile)
            except OSError:
                pass


Image.register_open(IptcImageFile.format, IptcImageFile)

Image.register_extension(IptcImageFile.format, ".iim")


def getiptcinfo(im):
    """
    Get IPTC information from TIFF, JPEG, or IPTC file.

    :param im: An image containing IPTC data.
    :returns: A dictionary containing IPTC information, or None if
        no IPTC information block was found.
    """
    import io

    from . import JpegImagePlugin, TiffImagePlugin

    data = None

    if isinstance(im, IptcImageFile):
        # return info dictionary right away
        return im.info

    elif isinstance(im, JpegImagePlugin.JpegImageFile):
        # extract the IPTC/NAA resource
        photoshop = im.info.get("photoshop")
        if photoshop:
            data = photoshop.get(0x0404)

    elif isinstance(im, TiffImagePlugin.TiffImageFile):
        # get raw data from the IPTC/NAA tag (PhotoShop tags the data
        # as 4-byte integers, so we cannot use the get method...)
        try:
            data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]
        except (AttributeError, KeyError):
            pass

    if data is None:
        return None  # no properties

    # create an IptcImagePlugin object without initializing it
    class FakeImage:
        pass

    im = FakeImage()
    im.__class__ = IptcImageFile

    # parse the IPTC information chunk
    im.info = {}
    im.fp = io.BytesIO(data)

    try:
        im._open()
    except (IndexError, KeyError):
        pass  # expected failure

    return im.info

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
user