{
    "file_diffs": [
        {
            "old_file_content": "import pytest\nfrom PIL import GbrImagePlugin, Image\n\nfrom .helper import assert_image_equal\n\n\ndef test_invalid_file():\n    invalid_file = \"Tests/images/flower.jpg\"\n\n    with pytest.raises(SyntaxError):\n        GbrImagePlugin.GbrImageFile(invalid_file)\n\n\ndef test_gbr_file():\n    with Image.open(\"Tests/images/gbr.gbr\") as im:\n        with Image.open(\"Tests/images/gbr.png\") as target:\n            assert_image_equal(target, im)\n",
            "new_file_content": "import pytest\nfrom PIL import GbrImagePlugin, Image\n\nfrom .helper import assert_image_equal\n\n\ndef test_invalid_file():\n    invalid_file = \"Tests/images/flower.jpg\"\n\n    with pytest.raises(SyntaxError):\n        GbrImagePlugin.GbrImageFile(invalid_file)\n\n\ndef test_gbr_file():\n    with Image.open(\"Tests/images/gbr.gbr\") as im:\n        with Image.open(\"Tests/images/gbr.png\") as target:\n            assert_image_equal(target, im)\n\n\ndef test_multiple_load_operations():\n    with Image.open(\"Tests/images/gbr.gbr\") as im:\n        im.load()\n        im.load()\n        with Image.open(\"Tests/images/gbr.png\") as target:\n            assert_image_equal(target, im)\n",
            "header": {
                "file": {
                    "path": "Tests/test_file_gbr.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "f183390bc",
                "new_commit_hash": "b95970889",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/Tests/test_file_gbr.py"
            },
            "plus_file": {
                "path": "b/Tests/test_file_gbr.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 15,
                            "length": 3
                        },
                        "new_range": {
                            "start": 15,
                            "length": 11
                        },
                        "section": "def test_gbr_file():"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "    with Image.open(\"Tests/images/gbr.gbr\") as im:",
                                "type": "context"
                            },
                            {
                                "content": "        with Image.open(\"Tests/images/gbr.png\") as target:",
                                "type": "context"
                            },
                            {
                                "content": "            assert_image_equal(target, im)",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "def test_multiple_load_operations():",
                                "type": "added"
                            },
                            {
                                "content": "    with Image.open(\"Tests/images/gbr.gbr\") as im:",
                                "type": "added"
                            },
                            {
                                "content": "        im.load()",
                                "type": "added"
                            },
                            {
                                "content": "        im.load()",
                                "type": "added"
                            },
                            {
                                "content": "        with Image.open(\"Tests/images/gbr.png\") as target:",
                                "type": "added"
                            },
                            {
                                "content": "            assert_image_equal(target, im)",
                                "type": "added"
                            }
                        ]
                    },
                    "modified_entities": [],
                    "added_entities": [
                        {
                            "file_name": "Tests/test_file_gbr.py",
                            "type": "function",
                            "name": "test_multiple_load_operations",
                            "content": "def test_multiple_load_operations():\n    with Image.open(\"Tests/images/gbr.gbr\") as im:\n        im.load()\n        im.load()\n        with Image.open(\"Tests/images/gbr.png\") as target:\n            assert_image_equal(target, im)",
                            "ast_type_str": "FunctionDef",
                            "start_lineno": 20,
                            "end_lineno": 25,
                            "parent": null
                        }
                    ],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "#\n# The Python Imaging Library\n#\n# load a GIMP brush file\n#\n# History:\n#       96-03-14 fl     Created\n#       16-01-08 es     Version 2\n#\n# Copyright (c) Secret Labs AB 1997.\n# Copyright (c) Fredrik Lundh 1996.\n# Copyright (c) Eric Soroos 2016.\n#\n# See the README file for information on usage and redistribution.\n#\n#\n# See https://github.com/GNOME/gimp/blob/mainline/devel-docs/gbr.txt for\n# format documentation.\n#\n# This code Interprets version 1 and 2 .gbr files.\n# Version 1 files are obsolete, and should not be used for new\n#   brushes.\n# Version 2 files are saved by GIMP v2.8 (at least)\n# Version 3 files have a format specifier of 18 for 16bit floats in\n#   the color depth field. This is currently unsupported by Pillow.\n\nfrom . import Image, ImageFile\nfrom ._binary import i32be as i32\n\n\ndef _accept(prefix):\n    return len(prefix) >= 8 and i32(prefix[:4]) >= 20 and i32(prefix[4:8]) in (1, 2)\n\n\n##\n# Image plugin for the GIMP brush format.\n\n\nclass GbrImageFile(ImageFile.ImageFile):\n\n    format = \"GBR\"\n    format_description = \"GIMP brush file\"\n\n    def _open(self):\n        header_size = i32(self.fp.read(4))\n        version = i32(self.fp.read(4))\n        if header_size < 20:\n            raise SyntaxError(\"not a GIMP brush\")\n        if version not in (1, 2):\n            raise SyntaxError(\"Unsupported GIMP brush version: %s\" % version)\n\n        width = i32(self.fp.read(4))\n        height = i32(self.fp.read(4))\n        color_depth = i32(self.fp.read(4))\n        if width <= 0 or height <= 0:\n            raise SyntaxError(\"not a GIMP brush\")\n        if color_depth not in (1, 4):\n            raise SyntaxError(\"Unsupported GIMP brush color depth: %s\" % color_depth)\n\n        if version == 1:\n            comment_length = header_size - 20\n        else:\n            comment_length = header_size - 28\n            magic_number = self.fp.read(4)\n            if magic_number != b\"GIMP\":\n                raise SyntaxError(\"not a GIMP brush, bad magic number\")\n            self.info[\"spacing\"] = i32(self.fp.read(4))\n\n        comment = self.fp.read(comment_length)[:-1]\n\n        if color_depth == 1:\n            self.mode = \"L\"\n        else:\n            self.mode = \"RGBA\"\n\n        self._size = width, height\n\n        self.info[\"comment\"] = comment\n\n        # Image might not be small\n        Image._decompression_bomb_check(self.size)\n\n        # Data is an uncompressed block of w * h * bytes/pixel\n        self._data_size = width * height * color_depth\n\n    def load(self):\n        self.im = Image.core.new(self.mode, self.size)\n        self.frombytes(self.fp.read(self._data_size))\n\n\n#\n# registry\n\n\nImage.register_open(GbrImageFile.format, GbrImageFile, _accept)\nImage.register_extension(GbrImageFile.format, \".gbr\")\n",
            "new_file_content": "#\n# The Python Imaging Library\n#\n# load a GIMP brush file\n#\n# History:\n#       96-03-14 fl     Created\n#       16-01-08 es     Version 2\n#\n# Copyright (c) Secret Labs AB 1997.\n# Copyright (c) Fredrik Lundh 1996.\n# Copyright (c) Eric Soroos 2016.\n#\n# See the README file for information on usage and redistribution.\n#\n#\n# See https://github.com/GNOME/gimp/blob/mainline/devel-docs/gbr.txt for\n# format documentation.\n#\n# This code Interprets version 1 and 2 .gbr files.\n# Version 1 files are obsolete, and should not be used for new\n#   brushes.\n# Version 2 files are saved by GIMP v2.8 (at least)\n# Version 3 files have a format specifier of 18 for 16bit floats in\n#   the color depth field. This is currently unsupported by Pillow.\n\nfrom . import Image, ImageFile\nfrom ._binary import i32be as i32\n\n\ndef _accept(prefix):\n    return len(prefix) >= 8 and i32(prefix[:4]) >= 20 and i32(prefix[4:8]) in (1, 2)\n\n\n##\n# Image plugin for the GIMP brush format.\n\n\nclass GbrImageFile(ImageFile.ImageFile):\n\n    format = \"GBR\"\n    format_description = \"GIMP brush file\"\n\n    def _open(self):\n        header_size = i32(self.fp.read(4))\n        version = i32(self.fp.read(4))\n        if header_size < 20:\n            raise SyntaxError(\"not a GIMP brush\")\n        if version not in (1, 2):\n            raise SyntaxError(\"Unsupported GIMP brush version: %s\" % version)\n\n        width = i32(self.fp.read(4))\n        height = i32(self.fp.read(4))\n        color_depth = i32(self.fp.read(4))\n        if width <= 0 or height <= 0:\n            raise SyntaxError(\"not a GIMP brush\")\n        if color_depth not in (1, 4):\n            raise SyntaxError(\"Unsupported GIMP brush color depth: %s\" % color_depth)\n\n        if version == 1:\n            comment_length = header_size - 20\n        else:\n            comment_length = header_size - 28\n            magic_number = self.fp.read(4)\n            if magic_number != b\"GIMP\":\n                raise SyntaxError(\"not a GIMP brush, bad magic number\")\n            self.info[\"spacing\"] = i32(self.fp.read(4))\n\n        comment = self.fp.read(comment_length)[:-1]\n\n        if color_depth == 1:\n            self.mode = \"L\"\n        else:\n            self.mode = \"RGBA\"\n\n        self._size = width, height\n\n        self.info[\"comment\"] = comment\n\n        # Image might not be small\n        Image._decompression_bomb_check(self.size)\n\n        # Data is an uncompressed block of w * h * bytes/pixel\n        self._data_size = width * height * color_depth\n\n    def load(self):\n        if self.im:\n            # Already loaded\n            return\n\n        self.im = Image.core.new(self.mode, self.size)\n        self.frombytes(self.fp.read(self._data_size))\n\n\n#\n# registry\n\n\nImage.register_open(GbrImageFile.format, GbrImageFile, _accept)\nImage.register_extension(GbrImageFile.format, \".gbr\")\n",
            "header": {
                "file": {
                    "path": "src/PIL/GbrImagePlugin.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "292de435c",
                "new_commit_hash": "f9d9cc772",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/src/PIL/GbrImagePlugin.py"
            },
            "plus_file": {
                "path": "b/src/PIL/GbrImagePlugin.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 84,
                            "length": 6
                        },
                        "new_range": {
                            "start": 84,
                            "length": 10
                        },
                        "section": "class GbrImageFile(ImageFile.ImageFile):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        self._data_size = width * height * color_depth",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    def load(self):",
                                "type": "context"
                            },
                            {
                                "content": "        if self.im:",
                                "type": "added"
                            },
                            {
                                "content": "            # Already loaded",
                                "type": "added"
                            },
                            {
                                "content": "            return",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "added"
                            },
                            {
                                "content": "        self.im = Image.core.new(self.mode, self.size)",
                                "type": "context"
                            },
                            {
                                "content": "        self.frombytes(self.fp.read(self._data_size))",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "src/PIL/GbrImagePlugin.py",
                            "type": "class",
                            "name": "GbrImageFile",
                            "content": "class GbrImageFile(ImageFile.ImageFile):\n\n    format = \"GBR\"\n    format_description = \"GIMP brush file\"\n\n    def _open(self):\n        header_size = i32(self.fp.read(4))\n        version = i32(self.fp.read(4))\n        if header_size < 20:\n            raise SyntaxError(\"not a GIMP brush\")\n        if version not in (1, 2):\n            raise SyntaxError(\"Unsupported GIMP brush version: %s\" % version)\n\n        width = i32(self.fp.read(4))\n        height = i32(self.fp.read(4))\n        color_depth = i32(self.fp.read(4))\n        if width <= 0 or height <= 0:\n            raise SyntaxError(\"not a GIMP brush\")\n        if color_depth not in (1, 4):\n            raise SyntaxError(\"Unsupported GIMP brush color depth: %s\" % color_depth)\n\n        if version == 1:\n            comment_length = header_size - 20\n        else:\n            comment_length = header_size - 28\n            magic_number = self.fp.read(4)\n            if magic_number != b\"GIMP\":\n                raise SyntaxError(\"not a GIMP brush, bad magic number\")\n            self.info[\"spacing\"] = i32(self.fp.read(4))\n\n        comment = self.fp.read(comment_length)[:-1]\n\n        if color_depth == 1:\n            self.mode = \"L\"\n        else:\n            self.mode = \"RGBA\"\n\n        self._size = width, height\n\n        self.info[\"comment\"] = comment\n\n        # Image might not be small\n        Image._decompression_bomb_check(self.size)\n\n        # Data is an uncompressed block of w * h * bytes/pixel\n        self._data_size = width * height * color_depth\n\n    def load(self):\n        if self.im:\n            # Already loaded\n            return\n\n        self.im = Image.core.new(self.mode, self.size)\n        self.frombytes(self.fp.read(self._data_size))",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 39,
                            "end_lineno": 92,
                            "parent": null
                        },
                        {
                            "file_name": "src/PIL/GbrImagePlugin.py",
                            "type": "method",
                            "name": "GbrImageFile.load",
                            "content": "class GbrImageFile(ImageFile.ImageFile):\n\n    format = \"GBR\"\n    format_description = \"GIMP brush file\"\n\n    def _open(self):\n        header_size = i32(self.fp.read(4))\n        version = i32(self.fp.read(4))\n        if header_size < 20:\n            raise SyntaxError(\"not a GIMP brush\")\n        if version not in (1, 2):\n            raise SyntaxError(\"Unsupported GIMP brush version: %s\" % version)\n\n        width = i32(self.fp.read(4))\n        height = i32(self.fp.read(4))\n        color_depth = i32(self.fp.read(4))\n        if width <= 0 or height <= 0:\n            raise SyntaxError(\"not a GIMP brush\")\n        if color_depth not in (1, 4):\n            raise SyntaxError(\"Unsupported GIMP brush color depth: %s\" % color_depth)\n\n        if version == 1:\n            comment_length = header_size - 20\n        else:\n            comment_length = header_size - 28\n            magic_number = self.fp.read(4)\n            if magic_number != b\"GIMP\":\n                raise SyntaxError(\"not a GIMP brush, bad magic number\")\n            self.info[\"spacing\"] = i32(self.fp.read(4))\n\n        comment = self.fp.read(comment_length)[:-1]\n\n        if color_depth == 1:\n            self.mode = \"L\"\n        else:\n            self.mode = \"RGBA\"\n\n        self._size = width, height\n\n        self.info[\"comment\"] = comment\n\n        # Image might not be small\n        Image._decompression_bomb_check(self.size)\n\n        # Data is an uncompressed block of w * h * bytes/pixel\n        self._data_size = width * height * color_depth\n\n    def load(self):\n        if self.im:\n            # Already loaded\n            return\n\n        self.im = Image.core.new(self.mode, self.size)\n        self.frombytes(self.fp.read(self._data_size))",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 86,
                            "end_lineno": 92,
                            "parent": {
                                "file_name": "src/PIL/GbrImagePlugin.py",
                                "type": "class",
                                "name": "GbrImageFile",
                                "content": "class GbrImageFile(ImageFile.ImageFile):\n\n    format = \"GBR\"\n    format_description = \"GIMP brush file\"\n\n    def _open(self):\n        header_size = i32(self.fp.read(4))\n        version = i32(self.fp.read(4))\n        if header_size < 20:\n            raise SyntaxError(\"not a GIMP brush\")\n        if version not in (1, 2):\n            raise SyntaxError(\"Unsupported GIMP brush version: %s\" % version)\n\n        width = i32(self.fp.read(4))\n        height = i32(self.fp.read(4))\n        color_depth = i32(self.fp.read(4))\n        if width <= 0 or height <= 0:\n            raise SyntaxError(\"not a GIMP brush\")\n        if color_depth not in (1, 4):\n            raise SyntaxError(\"Unsupported GIMP brush color depth: %s\" % color_depth)\n\n        if version == 1:\n            comment_length = header_size - 20\n        else:\n            comment_length = header_size - 28\n            magic_number = self.fp.read(4)\n            if magic_number != b\"GIMP\":\n                raise SyntaxError(\"not a GIMP brush, bad magic number\")\n            self.info[\"spacing\"] = i32(self.fp.read(4))\n\n        comment = self.fp.read(comment_length)[:-1]\n\n        if color_depth == 1:\n            self.mode = \"L\"\n        else:\n            self.mode = \"RGBA\"\n\n        self._size = width, height\n\n        self.info[\"comment\"] = comment\n\n        # Image might not be small\n        Image._decompression_bomb_check(self.size)\n\n        # Data is an uncompressed block of w * h * bytes/pixel\n        self._data_size = width * height * color_depth\n\n    def load(self):\n        if self.im:\n            # Already loaded\n            return\n\n        self.im = Image.core.new(self.mode, self.size)\n        self.frombytes(self.fp.read(self._data_size))",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 39,
                                "end_lineno": 92,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        }
    ],
    "old_commit_hash": "ac11fa7d1a7a15427c61de380bacfd0860141335^",
    "new_commit_hash": "ac11fa7d1a7a15427c61de380bacfd0860141335",
    "commit_message": "Merge pull request #4620 from ElinksFr/fix-gbr-image-loading\n\nFix repeatedly loading .gbr",
    "commit_date": "2020-05-17T11:34:58+10:00",
    "metadata": {}
}
{
    "repo_name": "pillow",
    "new_commit_hash": "ac11fa7d1a7a15427c61de380bacfd0860141335",
    "test_file_codes": [
        "import pytest\nfrom PIL import GbrImagePlugin, Image\n\nfrom .helper import assert_image_equal\n\n\ndef test_invalid_file():\n    invalid_file = \"Tests/images/flower.jpg\"\n\n    with pytest.raises(SyntaxError):\n        GbrImagePlugin.GbrImageFile(invalid_file)\n\n\ndef test_gbr_file():\n    with Image.open(\"Tests/images/gbr.gbr\") as im:\n        with Image.open(\"Tests/images/gbr.png\") as target:\n            assert_image_equal(target, im)\n\n\ndef test_multiple_load_operations():\n    with Image.open(\"Tests/images/gbr.gbr\") as im:\n        im.load()\n        im.load()\n        with Image.open(\"Tests/images/gbr.png\") as target:\n            assert_image_equal(target, im)\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 23ms\nInstalled 12 packages in 156ms\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 744ms\nPrepared 1 package in 32.47s\nInstalled 1 package in 3ms\n + pillow==7.2.0.dev0 (from file:///home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_ac11fa7d1a7a15427c61de380bacfd0860141335)\n",
    "new_commit_res_code": 0,
    "new_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.9.21, pytest-8.3.4, pluggy-1.5.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_ac11fa7d1a7a15427c61de380bacfd0860141335\nconfigfile: setup.cfg\nplugins: cov-6.0.0\ncollected 3 items\n\nr2e_tests/test_1.py ...                                                  [100%]\n\n==================================== PASSES ====================================\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::test_invalid_file\nPASSED r2e_tests/test_1.py::test_gbr_file\nPASSED r2e_tests/test_1.py::test_multiple_load_operations\n============================== 3 passed in 0.08s ===============================\n",
    "new_commit_res_stderr": "",
    "old_commit_res_code": 1,
    "old_commit_res_stdout": "============================= test session starts ==============================\nplatform linux -- Python 3.9.21, pytest-8.3.4, pluggy-1.5.0\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_ac11fa7d1a7a15427c61de380bacfd0860141335\nconfigfile: setup.cfg\nplugins: cov-6.0.0\ncollected 3 items\n\nr2e_tests/test_1.py ..F                                                  [100%]\n\n=================================== FAILURES ===================================\n________________________ test_multiple_load_operations _________________________\n\n    def test_multiple_load_operations():\n        with Image.open(\"Tests/images/gbr.gbr\") as im:\n            im.load()\n>           im.load()\n\nr2e_tests/test_1.py:23: \n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \nsrc/PIL/GbrImagePlugin.py:88: in load\n    self.frombytes(self.fp.read(self._data_size))\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n\nself = <PIL.GbrImagePlugin.GbrImageFile image mode=RGBA size=64x64 at 0x7568D0B6B1C0>\ndata = b'', decoder_name = 'raw', args = 'RGBA'\nd = <ImagingDecoder object at 0x7568d0c37150>, s = (0, 0)\n\n    def frombytes(self, data, decoder_name=\"raw\", *args):\n        \"\"\"\n        Loads this image with pixel data from a bytes object.\n    \n        This method is similar to the :py:func:`~PIL.Image.frombytes` function,\n        but loads data into this image instead of creating a new image object.\n        \"\"\"\n    \n        # may pass tuple instead of argument list\n        if len(args) == 1 and isinstance(args[0], tuple):\n            args = args[0]\n    \n        # default format\n        if decoder_name == \"raw\" and args == ():\n            args = self.mode\n    \n        # unpack data\n        d = _getdecoder(self.mode, decoder_name, args)\n        d.setimage(self.im)\n        s = d.decode(data)\n    \n        if s[0] >= 0:\n>           raise ValueError(\"not enough image data\")\nE           ValueError: not enough image data\n\nsrc/PIL/Image.py:800: ValueError\n==================================== PASSES ====================================\n=========================== short test summary info ============================\nPASSED r2e_tests/test_1.py::test_invalid_file\nPASSED r2e_tests/test_1.py::test_gbr_file\nFAILED r2e_tests/test_1.py::test_multiple_load_operations - ValueError: not e...\n========================= 1 failed, 2 passed in 0.10s ==========================\n",
    "old_commit_res_stderr": ""
}
Tests/test_file_gbr.py src/PIL/GbrImagePlugin.py
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** Error When Loading `.gbr` Images Multiple Times: `ValueError: not enough image data`

**Description:**
When attempting to load a `.gbr` image multiple times sequentially, the second load operation fails with a `ValueError`. This issue occurs because the image data is being loaded repeatedly, leading to insufficient image data for the second load.

**Example Buggy Code:**
```python
from PIL import Image

with Image.open("Tests/images/gbr.gbr") as im:
    im.load()
    im.load()  # This second load raises ValueError: not enough image data
```

**Expected Behavior:**
Loading a `.gbr` image multiple times should not cause any errors. The image should be loaded once, and subsequent load operations should recognize that the image is already loaded without attempting to reload the data.

**Actual Behavior:**
The second call to `im.load()` raises a `ValueError` with the message "not enough image data," indicating that the image data is being loaded repeatedly and is insufficient for multiple load operations.

[/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/GbrImagePlugin.py
#
# The Python Imaging Library
#
# load a GIMP brush file
#
# History:
#       96-03-14 fl     Created
#       16-01-08 es     Version 2
#
# Copyright (c) Secret Labs AB 1997.
# Copyright (c) Fredrik Lundh 1996.
# Copyright (c) Eric Soroos 2016.
#
# See the README file for information on usage and redistribution.
#
#
# See https://github.com/GNOME/gimp/blob/mainline/devel-docs/gbr.txt for
# format documentation.
#
# This code Interprets version 1 and 2 .gbr files.
# Version 1 files are obsolete, and should not be used for new
#   brushes.
# Version 2 files are saved by GIMP v2.8 (at least)
# Version 3 files have a format specifier of 18 for 16bit floats in
#   the color depth field. This is currently unsupported by Pillow.

from . import Image, ImageFile
from ._binary import i32be as i32


def _accept(prefix):
    return len(prefix) >= 8 and i32(prefix[:4]) >= 20 and i32(prefix[4:8]) in (1, 2)


##
# Image plugin for the GIMP brush format.


class GbrImageFile(ImageFile.ImageFile):

    format = "GBR"
    format_description = "GIMP brush file"

    def _open(self):
        header_size = i32(self.fp.read(4))
        version = i32(self.fp.read(4))
        if header_size < 20:
            raise SyntaxError("not a GIMP brush")
        if version not in (1, 2):
            raise SyntaxError("Unsupported GIMP brush version: %s" % version)

        width = i32(self.fp.read(4))
        height = i32(self.fp.read(4))
        color_depth = i32(self.fp.read(4))
        if width <= 0 or height <= 0:
            raise SyntaxError("not a GIMP brush")
        if color_depth not in (1, 4):
            raise SyntaxError("Unsupported GIMP brush color depth: %s" % color_depth)

        if version == 1:
            comment_length = header_size - 20
        else:
            comment_length = header_size - 28
            magic_number = self.fp.read(4)
            if magic_number != b"GIMP":
                raise SyntaxError("not a GIMP brush, bad magic number")
            self.info["spacing"] = i32(self.fp.read(4))

        comment = self.fp.read(comment_length)[:-1]

        if color_depth == 1:
            self.mode = "L"
        else:
            self.mode = "RGBA"

        self._size = width, height

        self.info["comment"] = comment

        # Image might not be small
        Image._decompression_bomb_check(self.size)

        # Data is an uncompressed block of w * h * bytes/pixel
        self._data_size = width * height * color_depth

    def load(self):
        self.im = Image.core.new(self.mode, self.size)
        self.frombytes(self.fp.read(self._data_size))


#
# registry


Image.register_open(GbrImageFile.format, GbrImageFile, _accept)
Image.register_extension(GbrImageFile.format, ".gbr")

```
--- 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:** Error When Loading `.gbr` Images Multiple Times: `ValueError: not enough image data`

**Description:**
When attempting to load a `.gbr` image multiple times sequentially, the second load operation fails with a `ValueError`. This issue occurs because the image data is being loaded repeatedly, leading to insufficient image data for the second load.

**Example Buggy Code:**
```python
from PIL import Image

with Image.open("Tests/images/gbr.gbr") as im:
    im.load()
    im.load()  # This second load raises ValueError: not enough image data
```

**Expected Behavior:**
Loading a `.gbr` image multiple times should not cause any errors. The image should be loaded once, and subsequent load operations should recognize that the image is already loaded without attempting to reload the data.

**Actual Behavior:**
The second call to `im.load()` raises a `ValueError` with the message "not enough image data," indicating that the image data is being loaded repeatedly and is insufficient for multiple load operations.

[/ISSUE]
{
    "test_invalid_file": "PASSED",
    "test_gbr_file": "PASSED",
    "test_multiple_load_operations": "PASSED"
}
diff --git a/src/PIL/GbrImagePlugin.py b/src/PIL/GbrImagePlugin.py
index 292de435c..f9d9cc772 100644
--- a/src/PIL/GbrImagePlugin.py
+++ b/src/PIL/GbrImagePlugin.py
@@ -84,6 +84,10 @@ class GbrImageFile(ImageFile.ImageFile):
         self._data_size = width * height * color_depth
 
     def load(self):
+        if self.im:
+            # Already loaded
+            return
+
         self.im = Image.core.new(self.mode, self.size)
         self.frombytes(self.fp.read(self._data_size))
 
 

{"src/PIL/GbrImagePlugin.py": "#\n# The Python Imaging Library\n#\n# load a GIMP brush file\n#\n# History:\n#       96-03-14 fl     Created\n#       16-01-08 es     Version 2\n#\n# Copyright (c) Secret Labs AB 1997.\n# Copyright (c) Fredrik Lundh 1996.\n# Copyright (c) Eric Soroos 2016.\n#\n# See the README file for information on usage and redistribution.\n#\n#\n# See https://github.com/GNOME/gimp/blob/mainline/devel-docs/gbr.txt for\n# format documentation.\n#\n# This code Interprets version 1 and 2 .gbr files.\n# Version 1 files are obsolete, and should not be used for new\n#   brushes.\n# Version 2 files are saved by GIMP v2.8 (at least)\n# Version 3 files have a format specifier of 18 for 16bit floats in\n#   the color depth field. This is currently unsupported by Pillow.\n\nfrom . import Image, ImageFile\nfrom ._binary import i32be as i32\n\n\ndef _accept(prefix):\n    return len(prefix) >= 8 and i32(prefix[:4]) >= 20 and i32(prefix[4:8]) in (1, 2)\n\n\n##\n# Image plugin for the GIMP brush format.\n\n\nclass GbrImageFile(ImageFile.ImageFile):\n\n    format = \"GBR\"\n    format_description = \"GIMP brush file\"\n\n    def _open(self):\n        header_size = i32(self.fp.read(4))\n        version = i32(self.fp.read(4))\n        if header_size < 20:\n            raise SyntaxError(\"not a GIMP brush\")\n        if version not in (1, 2):\n            raise SyntaxError(\"Unsupported GIMP brush version: %s\" % version)\n\n        width = i32(self.fp.read(4))\n        height = i32(self.fp.read(4))\n        color_depth = i32(self.fp.read(4))\n        if width <= 0 or height <= 0:\n            raise SyntaxError(\"not a GIMP brush\")\n        if color_depth not in (1, 4):\n            raise SyntaxError(\"Unsupported GIMP brush color depth: %s\" % color_depth)\n\n        if version == 1:\n            comment_length = header_size - 20\n        else:\n            comment_length = header_size - 28\n            magic_number = self.fp.read(4)\n            if magic_number != b\"GIMP\":\n                raise SyntaxError(\"not a GIMP brush, bad magic number\")\n            self.info[\"spacing\"] = i32(self.fp.read(4))\n\n        comment = self.fp.read(comment_length)[:-1]\n\n        if color_depth == 1:\n            self.mode = \"L\"\n        else:\n            self.mode = \"RGBA\"\n\n        self._size = width, height\n\n        self.info[\"comment\"] = comment\n\n        # Image might not be small\n        Image._decompression_bomb_check(self.size)\n\n        # Data is an uncompressed block of w * h * bytes/pixel\n        self._data_size = width * height * color_depth\n\n    def load(self):\n        self.im = Image.core.new(self.mode, self.size)\n        self.frombytes(self.fp.read(self._data_size))\n\n\n#\n# registry\n\n\nImage.register_open(GbrImageFile.format, GbrImageFile, _accept)\nImage.register_extension(GbrImageFile.format, \".gbr\")\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:** Error When Loading `.gbr` Images Multiple Times: `ValueError: not enough image data`

**Description:**
When attempting to load a `.gbr` image multiple times sequentially, the second load operation fails with a `ValueError`. This issue occurs because the image data is being loaded repeatedly, leading to insufficient image data for the second load.

**Example Buggy Code:**
```python
from PIL import Image

with Image.open("Tests/images/gbr.gbr") as im:
    im.load()
    im.load()  # This second load raises ValueError: not enough image data
```

**Expected Behavior:**
Loading a `.gbr` image multiple times should not cause any errors. The image should be loaded once, and subsequent load operations should recognize that the image is already loaded without attempting to reload the data.

**Actual Behavior:**
The second call to `im.load()` raises a `ValueError` with the message "not enough image data," indicating that the image data is being loaded repeatedly and is insufficient for multiple load operations.

[/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/GbrImagePlugin.py
#
# The Python Imaging Library
#
# load a GIMP brush file
#
# History:
#       96-03-14 fl     Created
#       16-01-08 es     Version 2
#
# Copyright (c) Secret Labs AB 1997.
# Copyright (c) Fredrik Lundh 1996.
# Copyright (c) Eric Soroos 2016.
#
# See the README file for information on usage and redistribution.
#
#
# See https://github.com/GNOME/gimp/blob/mainline/devel-docs/gbr.txt for
# format documentation.
#
# This code Interprets version 1 and 2 .gbr files.
# Version 1 files are obsolete, and should not be used for new
#   brushes.
# Version 2 files are saved by GIMP v2.8 (at least)
# Version 3 files have a format specifier of 18 for 16bit floats in
#   the color depth field. This is currently unsupported by Pillow.

from . import Image, ImageFile
from ._binary import i32be as i32


def _accept(prefix):
    return len(prefix) >= 8 and i32(prefix[:4]) >= 20 and i32(prefix[4:8]) in (1, 2)


##
# Image plugin for the GIMP brush format.


class GbrImageFile(ImageFile.ImageFile):

    format = "GBR"
    format_description = "GIMP brush file"

    def _open(self):
        header_size = i32(self.fp.read(4))
        version = i32(self.fp.read(4))
        if header_size < 20:
            raise SyntaxError("not a GIMP brush")
        if version not in (1, 2):
            raise SyntaxError("Unsupported GIMP brush version: %s" % version)

        width = i32(self.fp.read(4))
        height = i32(self.fp.read(4))
        color_depth = i32(self.fp.read(4))
        if width <= 0 or height <= 0:
            raise SyntaxError("not a GIMP brush")
        if color_depth not in (1, 4):
            raise SyntaxError("Unsupported GIMP brush color depth: %s" % color_depth)

        if version == 1:
            comment_length = header_size - 20
        else:
            comment_length = header_size - 28
            magic_number = self.fp.read(4)
            if magic_number != b"GIMP":
                raise SyntaxError("not a GIMP brush, bad magic number")
            self.info["spacing"] = i32(self.fp.read(4))

        comment = self.fp.read(comment_length)[:-1]

        if color_depth == 1:
            self.mode = "L"
        else:
            self.mode = "RGBA"

        self._size = width, height

        self.info["comment"] = comment

        # Image might not be small
        Image._decompression_bomb_check(self.size)

        # Data is an uncompressed block of w * h * bytes/pixel
        self._data_size = width * height * color_depth

    def load(self):
        self.im = Image.core.new(self.mode, self.size)
        self.frombytes(self.fp.read(self._data_size))


#
# registry


Image.register_open(GbrImageFile.format, GbrImageFile, _accept)
Image.register_extension(GbrImageFile.format, ".gbr")

```
--- 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