Merge "Remove invalid dict entries from hashes.pkl"
This commit is contained in:
commit
4316c53e4a
@ -360,6 +360,12 @@ def read_hashes(partition_dir):
|
||||
# given invalid input depending on the way in which the
|
||||
# input is invalid.
|
||||
pass
|
||||
|
||||
# Check for corrupted data that could break os.listdir()
|
||||
for suffix in hashes.keys():
|
||||
if not suffix.isalnum():
|
||||
return {'valid': False}
|
||||
|
||||
# hashes.pkl w/o valid updated key is "valid" but "forever old"
|
||||
hashes.setdefault('valid', True)
|
||||
hashes.setdefault('updated', -1)
|
||||
|
@ -8378,6 +8378,11 @@ class TestHashesHelpers(unittest.TestCase):
|
||||
# with the exactly the same value mutation from write_hashes
|
||||
self.assertEqual(hashes, result)
|
||||
|
||||
def test_ignore_corrupted_hashes(self):
|
||||
corrupted_hashes = {u'\x00\x00\x00': False, 'valid': True}
|
||||
diskfile.write_hashes(self.testdir, corrupted_hashes)
|
||||
result = diskfile.read_hashes(self.testdir)
|
||||
self.assertFalse(result['valid'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user