Skip to content

Commit 612fb01

Browse files
committed
fix: [favicon] Fix favicon display for negative MurmurHash values
1 parent 75d0665 commit 612fb01

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

bin/lib/objects/Favicons.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,18 @@ def create(self, content): # TODO first seen / last seen options
118118
dirname = os.path.dirname(filepath)
119119
if not os.path.exists(dirname):
120120
os.makedirs(dirname)
121-
print(filepath)
122121
with open(filepath, 'wb') as f:
123122
f.write(content)
124123
self._create()
125124

126125
def create(b_content, size_limit=5000000, b64=False, force=False):
127-
print(type(b_content))
128126
if isinstance(b_content, str):
129127
b_content = b_content.encode()
130-
print(type(b_content))
131128
b64 = base64.encodebytes(b_content) # newlines inserted after every 76 bytes of output
132129
favicon_id = str(mmh3.hash(b64))
133130
favicon = Favicon(favicon_id)
134-
# if not favicon.exists():
135-
favicon.create(b_content)
131+
if not favicon.exists():
132+
favicon.create(b_content)
136133
return favicon
137134

138135
class Favicons(AbstractDaterangeObjects):

var/www/blueprints/objects_favicon.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ def favicon(filename):
3737
if not filename:
3838
abort(404)
3939
filename = filename.replace('/', '')
40-
if not 9 <= len(filename) <= 11 or not filename.isascii() or not filename.isalnum():
40+
if not 9 <= len(filename) <= 11 or not filename.isascii():
4141
abort(404)
42+
if filename.startswith('-'):
43+
if not filename[1:].isalnum():
44+
abort(404)
45+
else:
46+
if not filename.isalnum():
47+
abort(404)
4248
fav = Favicons.Favicon(filename)
4349
return send_from_directory(Favicons.FAVICON_FOLDER, fav.get_rel_path(), as_attachment=False, mimetype='image')
4450

0 commit comments

Comments
 (0)