# Buggy code
def fixSubTableOverFlows(ttf, overflowRecord):
    """
    An offset has overflowed within a sub-table. We need to divide this subtable into smaller parts.
    """
    ok = 0
    table = ttf[overflowRecord.tableType].table
    lookup = table.LookupList.Lookup[overflowRecord.LookupListIndex]
    subIndex = overflowRecord.SubTableIndex
    subtable = lookup.SubTable[subIndex]

    # First, try not sharing anything for this subtable...
    if not hasattr(subtable, "DontShare"):
        subtable.DontShare = True
        return True

    if hasattr(subtable, "ExtSubTable"):
        # We split the subtable of the Extension table, and add a new Extension table
        # to contain the new subtable.

        subTableType = subtable.ExtSubTable.__class__.LookupType
        extSubTable = subtable
        subtable = extSubTable.ExtSubTable
        newExtSubTableClass = lookupTypes[overflowRecord.tableType][
            subtable.__class__.LookupType
        ]
        newExtSubTable = newExtSubTableClass()
        newExtSubTable.Format = extSubTable.Format
        lookup.SubTable.insert(subIndex + 1, newExtSubTable)

        newSubTableClass = lookupTypes[overflowRecord.tableType][subTableType]
        newSubTable = newSubTableClass()
        newExtSubTable.ExtSubTable = newSubTable
    else:
        subTableType = subtable.__class__.LookupType
        newSubTableClass = lookupTypes[overflowRecord.tableType][subTableType]
        newSubTable = newSubTableClass()
        lookup.SubTable.insert(subIndex + 1, newSubTable)

    if hasattr(lookup, "SubTableCount"):  # may not be defined yet.
        lookup.SubTableCount = lookup.SubTableCount + 1

    try:
        splitFunc = splitTable[overflowRecord.tableType][subTableType]
    except KeyError:
        return ok

    ok = splitFunc(subtable, newSubTable, overflowRecord)
    return ok


# Traceback (AssertionError)
Parsing 'GlyphOrder' table...
Parsing 'head' table...
Parsing 'hhea' table...
Parsing 'maxp' table...
Parsing 'OS/2' table...
Parsing 'name' table...
Parsing 'cmap' table...
Parsing 'post' table...
Parsing 'CFF ' table...
Parsing 'BASE' table...
Parsing 'GDEF' table...
Parsing 'GPOS' table...
Parsing 'GSUB' table...
Parsing 'hmtx' table...
Attempting to fix OTLOffsetOverflowError ('GPOS', 'LookupIndex:', 11, 'SubTableIndex:', None, 'ItemName:', None, 'ItemIndex:', None)
Attempting to fix OTLOffsetOverflowError ('GPOS', 'LookupIndex:', 10, 'SubTableIndex:', 1, 'ItemName:', 'Coverage', 'ItemIndex:', None)
Attempting to fix OTLOffsetOverflowError ('GPOS', 'LookupIndex:', 10, 'SubTableIndex:', 1, 'ItemName:', 'Coverage', 'ItemIndex:', None)
Traceback (most recent call last):
File "/fonttools/Lib/fontTools/ttx.py", line 383, in main
process(jobs, options)
File "/fonttools/Lib/fontTools/ttx.py", line 356, in process
action(input, output, options)
File "/fonttools/Lib/fontTools/misc/loggingTools.py", line 369, in wrapper
return func(*args, **kwds)
File "/fonttools/Lib/fontTools/ttx.py", line 277, in ttCompile
ttf.save(output)
File "/fonttools/Lib/fontTools/ttLib/__init__.py", line 216, in save
self._writeTable(tag, writer, done)
File "/fonttools/Lib/fontTools/ttLib/__init__.py", line 648, in _writeTable
tabledata = self.getTableData(tag)
File "/fonttools/Lib/fontTools/ttLib/__init__.py", line 659, in getTableData
return self.tables[tag].compile(self)
File "/fonttools/Lib/fontTools/ttLib/tables/otBase.py", line 90, in compile
self.table.compile(writer, font)
File "/fonttools/Lib/fontTools/ttLib/tables/otBase.py", line 660, in compile
conv.write(writer, font, table, value)
File "/fonttools/Lib/fontTools/ttLib/tables/otConverters.py", line 358, in write
value.compile(subWriter, font)
File "/fonttools/Lib/fontTools/ttLib/tables/otBase.py", line 635, in compile
conv.write(writer, font, table, value, i)
File "/fonttools/Lib/fontTools/ttLib/tables/otConverters.py", line 358, in write
value.compile(subWriter, font)
File "/fonttools/Lib/fontTools/ttLib/tables/otBase.py", line 635, in compile
conv.write(writer, font, table, value, i)
File "/fonttools/Lib/fontTools/ttLib/tables/otConverters.py", line 358, in write
value.compile(subWriter, font)
File "/fonttools/Lib/fontTools/ttLib/tables/otBase.py", line 618, in compile
writer['LookupType'].setValue(self.__class__.LookupType)
File "/fonttools/Lib/fontTools/ttLib/tables/otBase.py", line 514, in setValue
assert table[name] == value, (name, table[name], value)
AssertionError: (('LookupType', 9, 2), 'PairPos[2]', 'Lookup[10]', 'LookupList')

# Fixed code
def fixSubTableOverFlows(ttf, overflowRecord):
    """
    An offset has overflowed within a sub-table. We need to divide this subtable into smaller parts.
    """
    ok = 0
    table = ttf[overflowRecord.tableType].table
    lookup = table.LookupList.Lookup[overflowRecord.LookupListIndex]
    subIndex = overflowRecord.SubTableIndex
    subtable = lookup.SubTable[subIndex]

    # First, try not sharing anything for this subtable...
    if not hasattr(subtable, "DontShare"):
        subtable.DontShare = True
        return True

    if hasattr(subtable, "ExtSubTable"):
        # We split the subtable of the Extension table, and add a new Extension table
        # to contain the new subtable.

        subTableType = subtable.ExtSubTable.__class__.LookupType
        extSubTable = subtable
        subtable = extSubTable.ExtSubTable
        newExtSubTableClass = lookupTypes[overflowRecord.tableType][
            extSubTable.__class__.LookupType
        ]
        newExtSubTable = newExtSubTableClass()
        newExtSubTable.Format = extSubTable.Format
        lookup.SubTable.insert(subIndex + 1, newExtSubTable)

        newSubTableClass = lookupTypes[overflowRecord.tableType][subTableType]
        newSubTable = newSubTableClass()
        newExtSubTable.ExtSubTable = newSubTable
    else:
        subTableType = subtable.__class__.LookupType
        newSubTableClass = lookupTypes[overflowRecord.tableType][subTableType]
        newSubTable = newSubTableClass()
        lookup.SubTable.insert(subIndex + 1, newSubTable)

    if hasattr(lookup, "SubTableCount"):  # may not be defined yet.
        lookup.SubTableCount = lookup.SubTableCount + 1

    try:
        splitFunc = splitTable[overflowRecord.tableType][subTableType]
    except KeyError:
        return ok

    ok = splitFunc(subtable, newSubTable, overflowRecord)
    return ok