Merge "Remove invalid dict entries from hashes.pkl"

This commit is contained in:
Zuul 2019-06-17 20:38:45 +00:00 committed by Gerrit Code Review
commit 4316c53e4a
2 changed files with 11 additions and 0 deletions

View File

@ -360,6 +360,12 @@ def read_hashes(partition_dir):
# given invalid input depending on the way in which the # given invalid input depending on the way in which the
# input is invalid. # input is invalid.
pass 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.pkl w/o valid updated key is "valid" but "forever old"
hashes.setdefault('valid', True) hashes.setdefault('valid', True)
hashes.setdefault('updated', -1) hashes.setdefault('updated', -1)

View File

@ -8378,6 +8378,11 @@ class TestHashesHelpers(unittest.TestCase):
# with the exactly the same value mutation from write_hashes # with the exactly the same value mutation from write_hashes
self.assertEqual(hashes, result) 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__': if __name__ == '__main__':
unittest.main() unittest.main()