Merge "Remove invalid dict entries from hashes.pkl" into stable/stein

This commit is contained in:
Zuul 2019-08-17 04:31:48 +00:00 committed by Gerrit Code Review
commit 31a5bc909c
2 changed files with 11 additions and 0 deletions

View File

@ -354,6 +354,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

@ -8337,6 +8337,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()