Summary
Severity: High
File: sdk/basyx/aas/backend/local_file.py:163-164
Description
Two bugs on one line crash the iterator for any non-JSON file in the store directory.
for name in os.listdir(self.directory_path):
yield self.get_identifiable_by_hash(name.rstrip(".json"))
a) Wrong string method. str.rstrip(chars) strips any trailing character that appears in the chars string, not the literal suffix. For the .json argument, the character set is {'.', 'j', 's', 'o', 'n'}. On SHA-256 hex filenames this works by coincidence (hex chars a-f don't overlap), but any future change to the naming scheme or any filename whose hash ends in those characters would corrupt the key. The correct call is name.removesuffix(".json") (Python ≥ 3.9).
b) No extension filter. os.listdir() returns all directory entries: .DS_Store, temp files, subdirectories, etc. For non-.json entries, get_identifiable_by_hash() constructs a path like {dir}/{name}.json, which doesn't exist, and raises KeyError. One stray file in the store directory crashes the iterator.
Fix
for name in os.listdir(self.directory_path):
if name.endswith(".json"):
yield self.get_identifiable_by_hash(name.removesuffix(".json"))
Summary
Severity: High
File:
sdk/basyx/aas/backend/local_file.py:163-164Description
Two bugs on one line crash the iterator for any non-JSON file in the store directory.
a) Wrong string method.
str.rstrip(chars)strips any trailing character that appears in thecharsstring, not the literal suffix. For the.jsonargument, the character set is{'.', 'j', 's', 'o', 'n'}. On SHA-256 hex filenames this works by coincidence (hex charsa-fdon't overlap), but any future change to the naming scheme or any filename whose hash ends in those characters would corrupt the key. The correct call isname.removesuffix(".json")(Python ≥ 3.9).b) No extension filter.
os.listdir()returns all directory entries:.DS_Store, temp files, subdirectories, etc. For non-.jsonentries,get_identifiable_by_hash()constructs a path like{dir}/{name}.json, which doesn't exist, and raisesKeyError. One stray file in the store directory crashes the iterator.Fix