diff options
author | toonn <toonn@toonn.io> | 2020-07-07 20:29:31 +0200 |
---|---|---|
committer | toonn <toonn@toonn.io> | 2020-07-07 20:29:31 +0200 |
commit | 2637329b2d8ace6231c82258e072d3f800bf637d (patch) | |
tree | 391f7a83ec29fd409bce7743c6f8c82ae185c482 /ranger | |
parent | 8fd2e80148a75711e822e16d2edc87a1014527a8 (diff) | |
download | ranger-2637329b2d8ace6231c82258e072d3f800bf637d.tar.gz |
Hashlib requires objects implementing the buffer API
The hashes from python's hashlib only support objects that implement the buffer API. Bytes objects (python 2 string, python 3 string.encode()) are such objects. Passing fields from a stat object to a hash directly caused crashes whenever ranger checked for an image preview. Fixes #2032
Diffstat (limited to 'ranger')
-rw-r--r-- | ranger/core/actions.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py index 822594f4..854268a8 100644 --- a/ranger/core/actions.py +++ b/ranger/core/actions.py @@ -13,6 +13,7 @@ import re import shlex import shutil import string +import struct import tempfile from inspect import cleandoc from stat import S_IEXEC @@ -1049,9 +1050,9 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m @staticmethod def sha512_encode(path): stat_ = stat(path) - sha = sha512(stat_.st_dev) - sha.update(stat_.st_ino) - sha.update(stat_.st_mtime) + sha = sha512('{dev},{inode},{mtime}'.format( + dev=stat_.st_dev, inode=stat_.st_ino, mtime=stat_.st_mtime).encode( + 'utf-8', 'backslashreplace')) return '{0}.jpg'.format(sha.hexdigest()) def get_preview(self, fobj, width, height): # pylint: disable=too-many-return-statements |