You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HashTypeFactory.from_composite_str() raises AttributeError / IndexError instead of UnknownHashTypeException #1075
bugSomething isn't workingcontribContributed features not part of the core library.good first issueGood for newcomershelp wantedExtra attention is needed
HashTypeFactory.from_composite_str() documents Raises: UnknownHashTypeException if the type of hash cannot be determined, and raises UnknownHashTypeException on unknown prefixes such as unknown:.... However, it raises uncaught AttributeError on unsupported sha*/sha3*/blake2* prefixes (for example PyPI's blake2b_256 wheel digest key or PEP 691 sha224) and IndexError when : is missing after a known prefix, escaping except UnknownHashTypeException handlers (such as those in cyclonedx-python's requirements.py, pipenv.py, and poetry.py).
Reproduction
Using digests of six-1.17.0-py2.py3-none-any.whl from PyPI:
unknown -> UnknownHashTypeException: Unable to determine hash type from 'unknown:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274'
blake2b_256 -> AttributeError: BLAKE2B__256
sha224 -> AttributeError: SHA_224
md5 -> IndexError: list index out of range
Expected output
All four inputs raise UnknownHashTypeException, matching HashTypeFactory.from_hashlib_alg() and the Raises docstring on from_composite_str().
Root cause
In cyclonedx/contrib/hash/factories.py, HashTypeFactory.from_composite_str() indexes parts[1] without checking that : was present and calls getattr(HashAlgorithm, ...) on sha*, sha3*, and blake2* prefixes without guarding missing HashAlgorithm members.
Versions
cyclonedx-python-lib: 11.12.0 and main (3d62bf672340e5a0a3994b028e316033915ef53c)
Python: 3.11.2 on Linux 6.1.0-56-cloud-amd64 x86_64
Found with a differential-testing tool; the report was drafted with AI assistance and reviewed and edited by me.
changed the title [-]HashTypeFactory.from_composite_str() raises AttributeError / IndexError instead of UnknownHashTypeException[/-][+]`HashTypeFactory.from_composite_str()` raises AttributeError / IndexError instead of UnknownHashTypeException[/+]on Dec 2, 2026
bugSomething isn't workingcontribContributed features not part of the core library.good first issueGood for newcomershelp wantedExtra attention is needed
Activity
jkowalleck commentedon Nov 25, 2026
Debatable, but let's treat this as a bug.
a fix would not be a breaking change, as it is in the "contrib" area of the library.
this one is ready to be worked on.
CycloneDX Python library is a community effort - feel free to contribute to fix.
[-]HashTypeFactory.from_composite_str() raises AttributeError / IndexError instead of UnknownHashTypeException[/-][+]`HashTypeFactory.from_composite_str()` raises AttributeError / IndexError instead of UnknownHashTypeException[/+]