Skip to content

Fix asset deduplication logic#465

Merged
san-zrl merged 3 commits into
cbomkit:mainfrom
somiljain2006:Duplicate-reporting-issue
Jun 11, 2026
Merged

Fix asset deduplication logic#465
san-zrl merged 3 commits into
cbomkit:mainfrom
somiljain2006:Duplicate-reporting-issue

Conversation

@somiljain2006

Copy link
Copy Markdown
Contributor

Fixes #295

When processing certain Bouncy Castle block cipher constructions, multiple block-cipher-related nodes can be produced for the same source location. The existing deduplication logic relied on strict checks against the BlockCipher interface, which prevented some algorithm nodes from participating in reorganization even when they represented block-cipher assets.

This change updates the deduplication rule to operate on Algorithm nodes while preserving the existing BlockCipher node-kind filtering. It also adds null-safe handling for algorithm names and improves merging behavior when generic wrapper nodes are encountered.

Tests were added to cover:

  • overlapping block cipher roots generated from the Bouncy Castle engine and mode mappings
  • nested parent/child block cipher structures processed by the reorganizer

@somiljain2006
somiljain2006 requested a review from a team as a code owner June 8, 2026 20:54
Signed-off-by: somiljain2006 <[email protected]>
Signed-off-by: somiljain2006 <[email protected]>
@somiljain2006
somiljain2006 force-pushed the Duplicate-reporting-issue branch from 369c5e2 to 9d0f79b Compare June 8, 2026 20:54
@somiljain2006

Copy link
Copy Markdown
Contributor Author

@san-zrl Can you review this pr?

@san-zrl san-zrl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...

@san-zrl san-zrl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential Edge Cases NOT Covered:

  • Multiple overlapping roots: If 3+ algorithms overlap (e.g., AES, AES-128, AES-256 all detected), only one pair is processed per iteration. The reorganizer may need mu
  • Case sensitivity edge case: equalsIgnoreCase("Unknown") is used, but algorithm name comparison in isRelatedCipherFamily() uses case-sensitive equals(). This could cause issues if algorithm names have inconsistent casing.
  • Ambiguous prefix matching: "RC2" and "RC256" would be considered related (RC2 is prefix of RC256 followed by digit '5'), which may not be intended.
  • Child key conflicts: When merging children with toKeep.put(child), if both nodes have children of the same Kind, only one survives (the check !toKeep.getChildren().containsKey(child.getKind()) prevents overwriting, but the removed node's child is lost).
  • Empty name strings: While null is handled, empty strings ("") are not explicitly checked and could cause unexpected behavior in prefix matching.
  • Non-Algorithm BlockCipher nodes: The rule checks instanceof Algorithm but is registered for BlockCipher.class. If BlockCipher nodes exist that aren't Algorithms, they won't be deduplicated.

Recommendation

The implementation works correctly for the intended use case (BouncyCastle AES + CTR mode detection). However, consider:

  • Adding tests for multiple overlapping roots
  • Handling child merge conflicts more explicitly
  • Adding validation for edge cases in algorithm name matching
  • Documenting the reorganizer's behavior when multiple passes are needed

@san-zrl san-zrl self-assigned this Jun 9, 2026
@somiljain2006
somiljain2006 force-pushed the Duplicate-reporting-issue branch from d5fb3f5 to 40b857b Compare June 9, 2026 09:35
@somiljain2006
somiljain2006 requested a review from san-zrl June 9, 2026 09:39
@somiljain2006

Copy link
Copy Markdown
Contributor Author

@san-zrl Thanks for the review. I've addressed the reported edge cases:

  • Multiple overlapping roots: deduplication now runs iteratively until no more merges are possible, with test coverage for 3-node overlaps.
  • Case sensitivity: names are normalized before comparison.
  • Ambiguous prefix matching: The existing matching logic already requires a non-alphanumeric separator (which prevents cases like RC2 and RC256 from merging), so I have added a regression test to explicitly prove this behavior.
  • Empty names: handled explicitly with test coverage.

For the remaining points:

  • Child merge conflicts: existing children on the retained node are preserved, and only non-conflicting children are merged. This behavior is documented in the code.
  • Non-Algorithm BlockCipher nodes: the affected Bouncy Castle mappings are translated into Algorithm nodes, so restricting the scope to Algorithm is safe for this context.

@san-zrl san-zrl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks a lot.

@san-zrl
san-zrl merged commit cdfa0f7 into cbomkit:main Jun 11, 2026
2 checks passed
@somiljain2006
somiljain2006 deleted the Duplicate-reporting-issue branch June 11, 2026 12:26
@san-zrl san-zrl mentioned this pull request Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate findings?

2 participants