Browse Source

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

changes/12/682112/1
Zuul 1 month ago
parent
commit
31a5bc909c
2 changed files with 11 additions and 0 deletions
  1. 6
    0
      swift/obj/diskfile.py
  2. 5
    0
      test/unit/obj/test_diskfile.py

+ 6
- 0
swift/obj/diskfile.py View File

@@ -354,6 +354,12 @@ def read_hashes(partition_dir):
354 354
             # given invalid input depending on the way in which the
355 355
             # input is invalid.
356 356
             pass
357
+
358
+    # Check for corrupted data that could break os.listdir()
359
+    for suffix in hashes.keys():
360
+        if not suffix.isalnum():
361
+            return {'valid': False}
362
+
357 363
     # hashes.pkl w/o valid updated key is "valid" but "forever old"
358 364
     hashes.setdefault('valid', True)
359 365
     hashes.setdefault('updated', -1)

+ 5
- 0
test/unit/obj/test_diskfile.py View File

@@ -8337,6 +8337,11 @@ class TestHashesHelpers(unittest.TestCase):
8337 8337
         # with the exactly the same value mutation from write_hashes
8338 8338
         self.assertEqual(hashes, result)
8339 8339
 
8340
+    def test_ignore_corrupted_hashes(self):
8341
+        corrupted_hashes = {u'\x00\x00\x00': False, 'valid': True}
8342
+        diskfile.write_hashes(self.testdir, corrupted_hashes)
8343
+        result = diskfile.read_hashes(self.testdir)
8344
+        self.assertFalse(result['valid'])
8340 8345
 
8341 8346
 if __name__ == '__main__':
8342 8347
     unittest.main()

Loading…
Cancel
Save