# Buggy code
def __init__(self, rsrcmgr, spec, strict=settings.STRICT):
    try:
        self.basefont = literal_name(spec["BaseFont"])
    except KeyError:
        if strict:
            raise PDFFontError("BaseFont is missing")
        self.basefont = "unknown"
    self.cidsysteminfo = dict_value(spec.get("CIDSystemInfo", {}))
    self.cidcoding = "%s-%s" % (
        resolve1(self.cidsysteminfo.get("Registry", b"unknown")).decode("latin1"),
        resolve1(self.cidsysteminfo.get("Ordering", b"unknown")).decode("latin1"),
    )
    try:
        name = literal_name(spec["Encoding"])
    except KeyError:
        if strict:
            raise PDFFontError("Encoding is unspecified")
        name = "unknown"
    try:
        self.cmap = CMapDB.get_cmap(name)
    except CMapDB.CMapNotFound as e:
        if strict:
            raise PDFFontError(e)
        self.cmap = CMap()
    try:
        descriptor = dict_value(spec["FontDescriptor"])
    except KeyError:
        if strict:
            raise PDFFontError("FontDescriptor is missing")
        descriptor = {}
    ttf = None
    if "FontFile2" in descriptor:
        self.fontfile = stream_value(descriptor.get("FontFile2"))
        ttf = TrueTypeFont(self.basefont, BytesIO(self.fontfile.get_data()))
    self.unicode_map = None
    if "ToUnicode" in spec:
        strm = stream_value(spec["ToUnicode"])
        self.unicode_map = FileUnicodeMap()
        CMapParser(self.unicode_map, BytesIO(strm.get_data())).run()
    elif self.cidcoding in ("Adobe-Identity", "Adobe-UCS"):
        if ttf:
            try:
                self.unicode_map = ttf.create_unicode_map()
            except TrueTypeFont.CMapNotFound:
                pass
    else:
        try:
            self.unicode_map = CMapDB.get_unicode_map(
                self.cidcoding, self.cmap.is_vertical()
            )
        except CMapDB.CMapNotFound as e:
            pass

    self.vertical = self.cmap.is_vertical()
    if self.vertical:
        # writing mode: vertical
        widths = get_widths2(list_value(spec.get("W2", [])))
        self.disps = dict(
            (cid, (vx, vy)) for (cid, (_, (vx, vy))) in six.iteritems(widths)
        )
        (vy, w) = spec.get("DW2", [880, -1000])
        self.default_disp = (None, vy)
        widths = dict((cid, w) for (cid, (w, _)) in six.iteritems(widths))
        default_width = w
    else:
        # writing mode: horizontal
        self.disps = {}
        self.default_disp = 0
        widths = get_widths(list_value(spec.get("W", [])))
        default_width = spec.get("DW", 1000)
    PDFFont.__init__(self, descriptor, widths, default_width=default_width)
    return


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/felix/anaconda3/bin/pdf2txt.py", line 136, in <module>
if __name__ == '__main__': sys.exit(main())
File "/home/felix/anaconda3/bin/pdf2txt.py", line 131, in main
outfp = extract_text(**vars(A))
File "/home/felix/anaconda3/bin/pdf2txt.py", line 63, in extract_text
pdfminer.high_level.extract_text_to_fp(fp, **locals())
File "/home/felix/anaconda3/lib/python3.6/site-packages/pdfminer/high_level.py", line 82, in extract_text_to_fp
interpreter.process_page(page)
File "/home/felix/anaconda3/lib/python3.6/site-packages/pdfminer/pdfinterp.py", line 852, in process_page
self.render_contents(page.resources, page.contents, ctm=ctm)
File "/home/felix/anaconda3/lib/python3.6/site-packages/pdfminer/pdfinterp.py", line 862, in render_contents
self.init_resources(resources)
File "/home/felix/anaconda3/lib/python3.6/site-packages/pdfminer/pdfinterp.py", line 362, in init_resources
self.fontmap[fontid] = self.rsrcmgr.get_font(objid, spec)
File "/home/felix/anaconda3/lib/python3.6/site-packages/pdfminer/pdfinterp.py", line 212, in get_font
font = self.get_font(None, subspec)
File "/home/felix/anaconda3/lib/python3.6/site-packages/pdfminer/pdfinterp.py", line 203, in get_font
font = PDFCIDFont(self, spec)
File "/home/felix/anaconda3/lib/python3.6/site-packages/pdfminer/pdffont.py", line 658, in __init__
self.cmap = CMapDB.get_cmap(name)
File "/home/felix/anaconda3/lib/python3.6/site-packages/pdfminer/cmapdb.py", line 259, in get_cmap
data = klass._load_data(name)
File "/home/felix/anaconda3/lib/python3.6/site-packages/pdfminer/cmapdb.py", line 233, in _load_data
name = name.replace("\0", "")
AttributeError: 'PDFStream' object has no attribute 'replace'

# Fixed code
def __init__(self, rsrcmgr, spec, strict=settings.STRICT):
    try:
        self.basefont = literal_name(spec["BaseFont"])
    except KeyError:
        if strict:
            raise PDFFontError("BaseFont is missing")
        self.basefont = "unknown"
    self.cidsysteminfo = dict_value(spec.get("CIDSystemInfo", {}))
    self.cidcoding = "%s-%s" % (
        resolve1(self.cidsysteminfo.get("Registry", b"unknown")).decode("latin1"),
        resolve1(self.cidsysteminfo.get("Ordering", b"unknown")).decode("latin1"),
    )
    self.cmap = self.get_cmap_from_spec(spec, strict)

    try:
        descriptor = dict_value(spec["FontDescriptor"])
    except KeyError:
        if strict:
            raise PDFFontError("FontDescriptor is missing")
        descriptor = {}
    ttf = None
    if "FontFile2" in descriptor:
        self.fontfile = stream_value(descriptor.get("FontFile2"))
        ttf = TrueTypeFont(self.basefont, BytesIO(self.fontfile.get_data()))
    self.unicode_map = None
    if "ToUnicode" in spec:
        strm = stream_value(spec["ToUnicode"])
        self.unicode_map = FileUnicodeMap()
        CMapParser(self.unicode_map, BytesIO(strm.get_data())).run()
    elif self.cidcoding in ("Adobe-Identity", "Adobe-UCS"):
        if ttf:
            try:
                self.unicode_map = ttf.create_unicode_map()
            except TrueTypeFont.CMapNotFound:
                pass
    else:
        try:
            self.unicode_map = CMapDB.get_unicode_map(
                self.cidcoding, self.cmap.is_vertical()
            )
        except CMapDB.CMapNotFound as e:
            pass

    self.vertical = self.cmap.is_vertical()
    if self.vertical:
        # writing mode: vertical
        widths = get_widths2(list_value(spec.get("W2", [])))
        self.disps = dict(
            (cid, (vx, vy)) for (cid, (_, (vx, vy))) in six.iteritems(widths)
        )
        (vy, w) = spec.get("DW2", [880, -1000])
        self.default_disp = (None, vy)
        widths = dict((cid, w) for (cid, (w, _)) in six.iteritems(widths))
        default_width = w
    else:
        # writing mode: horizontal
        self.disps = {}
        self.default_disp = 0
        widths = get_widths(list_value(spec.get("W", [])))
        default_width = spec.get("DW", 1000)
    PDFFont.__init__(self, descriptor, widths, default_width=default_width)
    return