Skip to content

Commit 673cc07

Browse files
committed
Python3: fix crash bug when importing binary file (like jpeg). The
hyperdb content property inteprets the file as text and raises an error if the UTF-8 decode fails. To fix, read file as binary/byte and do conversion (ignoring errors) at the import level not the hyperdb level.
1 parent b002ab2 commit 673cc07

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

roundup/hyperdb.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1682,8 +1682,14 @@ def import_files(self, dirname, nodeid):
16821682
if not mime_type:
16831683
mime_type = self.default_mime_type
16841684
if props['content'].indexme:
1685+
index_content = self.get(nodeid, 'binary_content')
1686+
if bytes != str and isinstance(index_content, bytes):
1687+
index_content = index_content.decode('utf-8', errors='ignore')
1688+
# indexer will only index text mime type. It will skip
1689+
# other types. So if mime type of file is correct, we
1690+
# call add_text on content.
16851691
self.db.indexer.add_text((self.classname, nodeid, 'content'),
1686-
self.get(nodeid, 'content'), mime_type)
1692+
index_content, mime_type)
16871693

16881694
class Node:
16891695
""" A convenience wrapper for the given node

0 commit comments

Comments
 (0)