prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  ReemKufiInk crashes pyftsubset
  ```
  pyftsubset --text=duck --output-file=/tmp/reem.otf ReemKufiInk-Bold.otf
  
  Traceback (most recent call last):
    File "/tmp/venv/bin/pyftsubset", line 8, in <module>
      sys.exit(main())
    File "/tmp/venv/lib/python3.9/site-packages/fontTools/misc/loggingTools.py", line 372, in wrapper
      return func(*args, **kwds)
    File "/tmp/venv/lib/python3.9/site-packages/fontTools/subset/__init__.py", line 3104, in main
      subsetter.subset(font)
    File "/tmp/venv/lib/python3.9/site-packages/fontTools/subset/__init__.py", line 2908, in subset
      self._subset_glyphs(font)
    File "/tmp/venv/lib/python3.9/site-packages/fontTools/subset/__init__.py", line 2846, in _subset_glyphs
      retain = table.subset_glyphs(self)
    File "/tmp/venv/lib/python3.9/site-packages/fontTools/subset/__init__.py", line 2086, in subset_glyphs
      colorGlyphsV1 = unbuildColrV1(self.table.LayerList, self.table.BaseGlyphList)
    File "/tmp/venv/lib/python3.9/site-packages/fontTools/colorLib/unbuilder.py", line 6, in unbuildColrV1
      unbuilder = LayerListUnbuilder(layerV1List.Paint)
  AttributeError: 'NoneType' object has no attribute 'Paint'
  ```
  
  TTX handles the font just fine. File from https://github.com/aliftype/reem-kufi/commits/colr-v1 at 93d6dcd693ae42bb4295701e88a07cc4d04db73c
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `Lib/fontTools/colorLib/unbuilder.py`
  Content:
  ```
  1 from fontTools.ttLib.tables import otTables as ot
  2 from .table_builder import TableUnbuilder
  3 
  4 
  5 def unbuildColrV1(layerV1List, baseGlyphV1List):
  6     unbuilder = LayerListUnbuilder(layerV1List.Paint)
  7     return {
  8         rec.BaseGlyph: unbuilder.unbuildPaint(rec.Paint)
  9         for rec in baseGlyphV1List.BaseGlyphPaintRecord
  10     }
  11 
  12 
  13 def _flatten(lst):
  14     for el in lst:
  15         if isinstance(el, list):
  16             yield from _flatten(el)
  17         else:
  18             yield el
  19 
  20 
  21 class LayerListUnbuilder:
  22     def __init__(self, layers):
  23         self.layers = layers
  24 
  25         callbacks = {
  26             (
  27                 ot.Paint,
  28                 ot.PaintFormat.PaintColrLayers,
  29             ): self._unbuildPaintColrLayers,
  30         }
  31         self.tableUnbuilder = TableUnbuilder(callbacks)
  32 
  33     def unbuildPaint(self, paint):
  34         assert isinstance(paint, ot.Paint)
  35         return self.tableUnbuilder.unbuild(paint)
  36 
  37     def _unbuildPaintColrLayers(self, source):
  38         assert source["Format"] == ot.PaintFormat.PaintColrLayers
  39 
  40         layers = list(
  41             _flatten(
  42                 [
  43                     self.unbuildPaint(childPaint)
  44                     for childPaint in self.layers[
  45                         source["FirstLayerIndex"] : source["FirstLayerIndex"]
  46                         + source["NumLayers"]
  47                     ]
  48                 ]
  49             )
  50         )
  51 
  52         if len(layers) == 1:
  53             return layers[0]
  54 
  55         return {"Format": source["Format"], "Layers": layers}
  56 
  57 
  58 if __name__ == "__main__":
  59     from pprint import pprint
  60     import sys
  61     from fontTools.ttLib import TTFont
  62 
  63     try:
  64         fontfile = sys.argv[1]
  65     except IndexError:
  66         sys.exit("usage: fonttools colorLib.unbuilder FONTFILE")
  67 
  68     font = TTFont(fontfile)
  69     colr = font["COLR"]
  70     if colr.version < 1:
  71         sys.exit(f"error: No COLR table version=1 found in {fontfile}")
  72 
  73     colorGlyphs = unbuildColrV1(
  74         colr.table.LayerList,
  75         colr.table.BaseGlyphList,
  76         ignoreVarIdx=not colr.table.VarStore,
  77     )
  78 
  79     pprint(colorGlyphs)
  80
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/Lib/fontTools/colorLib/unbuilder.py b/Lib/fontTools/colorLib/unbuilder.py
  --- a/Lib/fontTools/colorLib/unbuilder.py
  +++ b/Lib/fontTools/colorLib/unbuilder.py
  @@ -2,11 +2,14 @@
   from .table_builder import TableUnbuilder
   
   
  -def unbuildColrV1(layerV1List, baseGlyphV1List):
  -    unbuilder = LayerListUnbuilder(layerV1List.Paint)
  +def unbuildColrV1(layerList, baseGlyphList):
  +    layers = []
  +    if layerList:
  +        layers = layerList.Paint
  +    unbuilder = LayerListUnbuilder(layers)
       return {
           rec.BaseGlyph: unbuilder.unbuildPaint(rec.Paint)
  -        for rec in baseGlyphV1List.BaseGlyphPaintRecord
  +        for rec in baseGlyphList.BaseGlyphPaintRecord
       }
  
verification_info: {"golden_diff": "diff --git a/Lib/fontTools/colorLib/unbuilder.py b/Lib/fontTools/colorLib/unbuilder.py\n--- a/Lib/fontTools/colorLib/unbuilder.py\n+++ b/Lib/fontTools/colorLib/unbuilder.py\n@@ -2,11 +2,14 @@\n from .table_builder import TableUnbuilder\n \n \n-def unbuildColrV1(layerV1List, baseGlyphV1List):\n-    unbuilder = LayerListUnbuilder(layerV1List.Paint)\n+def unbuildColrV1(layerList, baseGlyphList):\n+    layers = []\n+    if layerList:\n+        layers = layerList.Paint\n+    unbuilder = LayerListUnbuilder(layers)\n     return {\n         rec.BaseGlyph: unbuilder.unbuildPaint(rec.Paint)\n-        for rec in baseGlyphV1List.BaseGlyphPaintRecord\n+        for rec in baseGlyphList.BaseGlyphPaintRecord\n     }\n", "issue": "ReemKufiInk crashes pyftsubset\n```\r\npyftsubset --text=duck --output-file=/tmp/reem.otf ReemKufiInk-Bold.otf\r\n\r\nTraceback (most recent call last):\r\n  File \"/tmp/venv/bin/pyftsubset\", line 8, in <module>\r\n    sys.exit(main())\r\n  File \"/tmp/venv/lib/python3.9/site-packages/fontTools/misc/loggingTools.py\", line 372, in wrapper\r\n    return func(*args, **kwds)\r\n  File \"/tmp/venv/lib/python3.9/site-packages/fontTools/subset/__init__.py\", line 3104, in main\r\n    subsetter.subset(font)\r\n  File \"/tmp/venv/lib/python3.9/site-packages/fontTools/subset/__init__.py\", line 2908, in subset\r\n    self._subset_glyphs(font)\r\n  File \"/tmp/venv/lib/python3.9/site-packages/fontTools/subset/__init__.py\", line 2846, in _subset_glyphs\r\n    retain = table.subset_glyphs(self)\r\n  File \"/tmp/venv/lib/python3.9/site-packages/fontTools/subset/__init__.py\", line 2086, in subset_glyphs\r\n    colorGlyphsV1 = unbuildColrV1(self.table.LayerList, self.table.BaseGlyphList)\r\n  File \"/tmp/venv/lib/python3.9/site-packages/fontTools/colorLib/unbuilder.py\", line 6, in unbuildColrV1\r\n    unbuilder = LayerListUnbuilder(layerV1List.Paint)\r\nAttributeError: 'NoneType' object has no attribute 'Paint'\r\n```\r\n\r\nTTX handles the font just fine. File from https://github.com/aliftype/reem-kufi/commits/colr-v1 at 93d6dcd693ae42bb4295701e88a07cc4d04db73c\n", "before_files": [{"content": "from fontTools.ttLib.tables import otTables as ot\nfrom .table_builder import TableUnbuilder\n\n\ndef unbuildColrV1(layerV1List, baseGlyphV1List):\n    unbuilder = LayerListUnbuilder(layerV1List.Paint)\n    return {\n        rec.BaseGlyph: unbuilder.unbuildPaint(rec.Paint)\n        for rec in baseGlyphV1List.BaseGlyphPaintRecord\n    }\n\n\ndef _flatten(lst):\n    for el in lst:\n        if isinstance(el, list):\n            yield from _flatten(el)\n        else:\n            yield el\n\n\nclass LayerListUnbuilder:\n    def __init__(self, layers):\n        self.layers = layers\n\n        callbacks = {\n            (\n                ot.Paint,\n                ot.PaintFormat.PaintColrLayers,\n            ): self._unbuildPaintColrLayers,\n        }\n        self.tableUnbuilder = TableUnbuilder(callbacks)\n\n    def unbuildPaint(self, paint):\n        assert isinstance(paint, ot.Paint)\n        return self.tableUnbuilder.unbuild(paint)\n\n    def _unbuildPaintColrLayers(self, source):\n        assert source[\"Format\"] == ot.PaintFormat.PaintColrLayers\n\n        layers = list(\n            _flatten(\n                [\n                    self.unbuildPaint(childPaint)\n                    for childPaint in self.layers[\n                        source[\"FirstLayerIndex\"] : source[\"FirstLayerIndex\"]\n                        + source[\"NumLayers\"]\n                    ]\n                ]\n            )\n        )\n\n        if len(layers) == 1:\n            return layers[0]\n\n        return {\"Format\": source[\"Format\"], \"Layers\": layers}\n\n\nif __name__ == \"__main__\":\n    from pprint import pprint\n    import sys\n    from fontTools.ttLib import TTFont\n\n    try:\n        fontfile = sys.argv[1]\n    except IndexError:\n        sys.exit(\"usage: fonttools colorLib.unbuilder FONTFILE\")\n\n    font = TTFont(fontfile)\n    colr = font[\"COLR\"]\n    if colr.version < 1:\n        sys.exit(f\"error: No COLR table version=1 found in {fontfile}\")\n\n    colorGlyphs = unbuildColrV1(\n        colr.table.LayerList,\n        colr.table.BaseGlyphList,\n        ignoreVarIdx=not colr.table.VarStore,\n    )\n\n    pprint(colorGlyphs)\n", "path": "Lib/fontTools/colorLib/unbuilder.py"}], "after_files": [{"content": "from fontTools.ttLib.tables import otTables as ot\nfrom .table_builder import TableUnbuilder\n\n\ndef unbuildColrV1(layerList, baseGlyphList):\n    layers = []\n    if layerList:\n        layers = layerList.Paint\n    unbuilder = LayerListUnbuilder(layers)\n    return {\n        rec.BaseGlyph: unbuilder.unbuildPaint(rec.Paint)\n        for rec in baseGlyphList.BaseGlyphPaintRecord\n    }\n\n\ndef _flatten(lst):\n    for el in lst:\n        if isinstance(el, list):\n            yield from _flatten(el)\n        else:\n            yield el\n\n\nclass LayerListUnbuilder:\n    def __init__(self, layers):\n        self.layers = layers\n\n        callbacks = {\n            (\n                ot.Paint,\n                ot.PaintFormat.PaintColrLayers,\n            ): self._unbuildPaintColrLayers,\n        }\n        self.tableUnbuilder = TableUnbuilder(callbacks)\n\n    def unbuildPaint(self, paint):\n        assert isinstance(paint, ot.Paint)\n        return self.tableUnbuilder.unbuild(paint)\n\n    def _unbuildPaintColrLayers(self, source):\n        assert source[\"Format\"] == ot.PaintFormat.PaintColrLayers\n\n        layers = list(\n            _flatten(\n                [\n                    self.unbuildPaint(childPaint)\n                    for childPaint in self.layers[\n                        source[\"FirstLayerIndex\"] : source[\"FirstLayerIndex\"]\n                        + source[\"NumLayers\"]\n                    ]\n                ]\n            )\n        )\n\n        if len(layers) == 1:\n            return layers[0]\n\n        return {\"Format\": source[\"Format\"], \"Layers\": layers}\n\n\nif __name__ == \"__main__\":\n    from pprint import pprint\n    import sys\n    from fontTools.ttLib import TTFont\n\n    try:\n        fontfile = sys.argv[1]\n    except IndexError:\n        sys.exit(\"usage: fonttools colorLib.unbuilder FONTFILE\")\n\n    font = TTFont(fontfile)\n    colr = font[\"COLR\"]\n    if colr.version < 1:\n        sys.exit(f\"error: No COLR table version=1 found in {fontfile}\")\n\n    colorGlyphs = unbuildColrV1(\n        colr.table.LayerList,\n        colr.table.BaseGlyphList,\n        ignoreVarIdx=not colr.table.VarStore,\n    )\n\n    pprint(colorGlyphs)\n", "path": "Lib/fontTools/colorLib/unbuilder.py"}]}