fix(core): parse single letter version suffixes without a period - #8728
fix(core): parse single letter version suffixes without a period#8728Eljees wants to merge 2 commits into
Conversation
DependencyVersionUtil uses two expressions to extract a version from a name: RX_VERSION, which requires a period, and RX_SINGLE_VERSION, which does not. Only the first one accepts a single trailing letter, so a version written as one digit followed by one letter - the scheme libjpeg uses (8a, 9d, 9e) - loses the letter and is parsed as "9". The CPE analyzer then matches every CPE for version 9, among them the vulnerable 9a and 9c, and reports false positives; the reporter of the issue had to work around it with a hint file. This adds the missing alternative to RX_SINGLE_VERSION so that both expressions accept the same suffixes. The flags of the pattern are left alone on purpose, so the change is limited to the case described above. fixes dependency-check#4139
There was a problem hiding this comment.
Pull request overview
Updates version parsing to preserve single-letter suffixes used by libjpeg.
Changes:
- Extends
RX_SINGLE_VERSIONto recognize versions such as8aand9e. - Adds regression tests for standalone and filename-embedded versions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
DependencyVersionUtil.java |
Adds single-letter suffix parsing. |
DependencyVersionUtilTest.java |
Tests libjpeg version formats. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
chadlwilson
left a comment
There was a problem hiding this comment.
Probably OK if the tests all pass?
Not really sure though, hard to understand what the consequence of changing this logic is downstream and whether it will lead to correct matching since the (presumably naive AI generated) PR does not demonstrate any end-user functionality improvement (being able to match libjpeg correctly to vulns), and the version parsing has additional risk given it is used in all sorts of places - sometimes needing consistency with separate CPE version sorting/parsing rules for version "piece" or range matching and also compatibility with weird hacks in CPEAnalyzer like:
The PR only showed the parser output, not what it changes for a user. The
comparison that matters is the one CPEAnalyzer performs when it looks for an
exact CPE match:
parseVersion(evidence).equals(parseVersion(cpe.getVersion()))
Both sides went through the same expression, so dropping the suffix did not
stop libjpeg from matching - it made 8a and 8b indistinguishable. A dependency
at 8a matched the CPE of 8b and the identified version printed in the report
was "8".
Measured on this branch and on its parent:
parseVersion("libjpeg-turbo-8a.tar.gz") before: 8 after: 8a
parseVersion("8b") before: 8 after: 8b
8a evidence equals 8b CPE before: true after: false
The new test pins that down.
Signed-off-by: Eljees <3.14hell@gmail.com>
|
Fair point — the tests asserted the parser output, not the thing that matters. Measured on this branch against its parent:
The last row is the user-visible effect. On the downstream risk: any version that parsed before parses identically — |
Description of Change
DependencyVersionUtilhas two expressions for pulling a version out of a name:RX_VERSION, which requires a period, andRX_SINGLE_VERSION, which does not. Only the first one accepts a single trailing letter, so libjpeg's scheme of one digit and one letter (8a,9d,9e) never reaches it — the name falls through toRX_SINGLE_VERSION, the letter is dropped and the version comes out as9. The CPE analyzer then matches every CPE for version 9, among them the vulnerable9aand9c, which is the false positive described in the issue. The reporter had to work around it with a hint file.The change adds the missing alternative to
RX_SINGLE_VERSIONso that both expressions accept the same suffixes. I left the pattern flags alone on purpose:RX_VERSIONisCASE_INSENSITIVEandRX_SINGLE_VERSIONis not, and adding the flag would also have changed how the other alternatives match, which is outside the scope of this issue.Before changing anything I ran the current and the proposed expression side by side over the names used in the existing tests (
commons-lang3-3.12.0.jar,spring-core-5.3.9.RELEASE.jar,openssl-1.0.2k,lib1.5r4-someflag-R26.jar,6,utf8, ...). Only inputs of the "digit followed by a single letter" shape change; everything else parses exactly as before.Related issues
Have test cases been added to cover the new functionality?
yes —
DependencyVersionUtilTest.testParseVersion_singleLetterSuffixWithoutPeriod, covering9e,9d,8aand the two names from the reporter's reproducer. Onmainit fails withexpected: <9e> but was: <9>.