This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jgoerzen
Recipients jgoerzen
Date 2019-11-20.15:07:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1574262469.06.0.509781459017.issue38864@roundup.psfhosted.org>
In-reply-to
Content
This simple recipe fails:

>>> import dbm
>>> dbm.open(b"foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/dbm/__init__.py", line 78, in open
    result = whichdb(file) if 'n' not in flag else None
  File "/usr/lib/python3.7/dbm/__init__.py", line 112, in whichdb
    f = io.open(filename + ".pag", "rb")
TypeError: can't concat str to bytes

Why does this matter?  On POSIX, a filename is any string of bytes that does not contain 0x00 or '/'.  A database with a filename containing, for instance, German characters in ISO-8859-1, can't be opened by dbm, EVEN WITH decoding.

For instance:

file = b"test\xf7"
>>> dbm.open(file.decode())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf7 in position 4: invalid start byte
db = dbm.open(file.decode('iso-8859-1'), 'c')
db.close()

Then:

ls *.db | hd
00000000  74 65 73 74 c3 b7 2e 64  62 0a                    |test...db.|
0000000a

Note that it didn't insert the 0xf7 here; rather, it inserted the Unicode sequence corresponding to the division character (which is what 0xf7 in iso-8859-1 is).  It is not possible to open a filename named "test\xf7.db" with the dbm module.
History
Date User Action Args
2019-11-20 15:07:49jgoerzensetrecipients: + jgoerzen
2019-11-20 15:07:49jgoerzensetmessageid: <1574262469.06.0.509781459017.issue38864@roundup.psfhosted.org>
2019-11-20 15:07:49jgoerzenlinkissue38864 messages
2019-11-20 15:07:48jgoerzencreate