Closed Malcolmnixon closed 5 months ago
@Malcolmnixon Thanks for finding this and providing a description of the different scenarios .
I have added an extra check in the add_files function to check for an empty file list.
There is also a corresponding issue with the add_packages function which I have also fixed.
The
SBOM.get_files()
function is typed as returning a List: https://github.com/anthonyharrison/lib4sbom/blob/45c891cb64148f16f722fbc39b12b7f1fb253a57/lib4sbom/sbom.py#L64-L68The
SBOM.add_files()
function takes a dictionary of files and stores the dictionary of files: https://github.com/anthonyharrison/lib4sbom/blob/45c891cb64148f16f722fbc39b12b7f1fb253a57/lib4sbom/sbom.py#L29-L30The three scenarios that can occur are:
SBOM.get_files()
is called whenSBOM.add_files()
has not been calledSBOM.get_files()
is called whenSBOM.add_files()
has been called with an empty dictionary (no files)SBOM.get_files()
is called whenSBOM.add_files()
has been called with a dictionary containing 1 or more filesIn case 1 the function returns a List because "files" is not in the dictionary, and so a default List is returned. In case 3 the function returns a List because the list-comprehension generates a new list. In case 2 the function returns a Dictionary because the dictionary is empty and so is returned unmodified.
This is resulting in a crash of in the https://github.com/anthonyharrison/sbommerge utility. Specifically if it's provided an SBOM with an empty file list, it gets a dictionary rather than a list, and its iteration throws due to getting an unexpected type.