Skip to content

Commit a20eb7b

Browse files
committed
[PGPRO-146] pgdata_content: checksum for truncated cfm
1 parent 302db1c commit a20eb7b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tests/helpers/ptrack_helpers.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,8 +1709,18 @@ def pgdata_content(self, pgdata, ignore_ptrack=True, exclude_dirs=None):
17091709
file_relpath = os.path.relpath(file_fullpath, pgdata)
17101710
directory_dict['files'][file_relpath] = {'is_datafile': False}
17111711
with open(file_fullpath, 'rb') as f:
1712-
directory_dict['files'][file_relpath]['md5'] = hashlib.md5(f.read()).hexdigest()
1713-
f.close()
1712+
content = f.read()
1713+
# truncate cfm's content's zero tail
1714+
if file_relpath.endswith('.cfm'):
1715+
zero64 = b"\x00"*64
1716+
l = len(content)
1717+
while l > 64:
1718+
s = (l - 1) & ~63
1719+
if content[s:l] != zero64[:l-s]:
1720+
break
1721+
l = s
1722+
content = content[:l]
1723+
directory_dict['files'][file_relpath]['md5'] = hashlib.md5(content).hexdigest()
17141724
# directory_dict['files'][file_relpath]['md5'] = hashlib.md5(
17151725
# f = open(file_fullpath, 'rb').read()).hexdigest()
17161726

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy