Skip to content

Fix/sp 4350 skip fh2 winnowing hpsm binary files - #147

Merged
agustingroh merged 2 commits into
mainfrom
fix/SP-4350-skip-fh2-winnowing-HPSM-binary-files
Apr 28, 2026
Merged

Fix/sp 4350 skip fh2 winnowing hpsm binary files#147
agustingroh merged 2 commits into
mainfrom
fix/SP-4350-skip-fh2-winnowing-HPSM-binary-files

Conversation

@agustingroh

@agustingroh agustingroh commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Resolved crashes when fingerprinting large binary files
    • Fixed invalid array length errors during scanning operations
  • Improvements

    • Implemented binary file detection to optimize fingerprint calculations
    • Binary content now skips redundant hash computations for improved performance
  • Chores

    • Version bumped to 0.40.0

@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@agustingroh has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 19 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f5181df5-800f-4d51-a9e6-2afe2976dd12

📥 Commits

Reviewing files that changed from the base of the PR and between bdd44fd and 48e9674.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • package.json
  • src/cli/commands/wfp.ts
  • src/sdk/scanner/Scannable/ScannableItem.ts
  • src/sdk/scanner/WfpProvider/WfpCalculator/WfpCalculator.ts
📝 Walkthrough

Walkthrough

Version 0.40.0 introduces binary file detection and handling to the WfpCalculator. Binary files are now identified via isBinaryFileSync, with an isBinary flag propagated through ScannableItem to fingerprint computation, where certain hash computations and line-derived components are conditionally skipped for binary content.

Changes

Cohort / File(s) Summary
Documentation & Version
CHANGELOG.md, package.json
Version incremented to 0.40.0 with changelog entries documenting WfpCalculator behavioral changes for binary files.
Binary Flag Propagation
src/sdk/scanner/Scannable/ScannableItem.ts
Added isBinary boolean field and optional constructor parameter (default false) to carry binary-file indicator through the scanning pipeline.
Binary-Aware Fingerprinting
src/sdk/scanner/WfpProvider/WfpCalculator/WfpCalculator.ts
Integrated binary detection via isBinaryFileSync; updated fingerprint computation functions to accept isBinary flag and conditionally disable line/code-derived hash components (fh2, calc_wfp, HPSM joining) for binary content, resulting in MD5-only output.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A binary whisper through the code,
No crashes now on heavy load,
MD5 marks the simple way,
While complex hashes fade away.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is specific and directly related to the main change: it identifies the issue (SP-4350) and describes the key functional change (skipping fh2 winnowing HPSM for binary files), which aligns with the changeset's focus on binary file handling in the WfpCalculator.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/SP-4350-skip-fh2-winnowing-HPSM-binary-files

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/sdk/scanner/WfpProvider/WfpCalculator/WfpCalculator.ts (2)

295-320: Binary short-circuit logic looks correct.

Threading isBinary through the three fingerprint entry points and bypassing both calc_wfp (snippet winnowing) and calculate_opposite_line_ending_hash (fh2=) is the right call — both are line/code-derived and have no meaning on binary content. The HPSM path also correctly returns just the file= line wrapped in truncate_string, matching the documented behavior in CHANGELOG.md (binary files emit only file= MD5).

One small observation: there are no unit tests in this PR exercising the binary path through wfp_for_content / wfp_hpsm_for_content / wfp_only_md5. Given the regression this fix targets (RangeError: Invalid array length on large binaries) and the three new branches, a focused test that asserts (a) no fh2= line, (b) no winnowing lines, and (c) correct file=md5,size,path for a binary buffer would be valuable to lock the behavior in.

Want me to draft a test fixture (e.g. a small synthetic buffer with a NUL byte) and a spec covering all three winnowing modes?

Also applies to: 427-441

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/sdk/scanner/WfpProvider/WfpCalculator/WfpCalculator.ts` around lines 295
- 320, Add unit tests covering the binary path through wfp_for_content,
wfp_hpsm_for_content, and wfp_only_md5: create a small synthetic binary Buffer
(e.g., includes a NUL byte) and call each function with isBinary=true and a
representative maxSize; assert the output contains only the file=md5,size,path
line (correct MD5 and size) and does NOT contain fh2= or any winnowing/snippet
lines produced by calc_wfp or HPSM; include separate assertions for each
function to lock the three branches and prevent regressions like the RangeError
on large binaries.

595-595: Pass the in-memory content buffer to avoid redundant file I/O.

Since content is already loaded from disk on line 594, passing path to isBinaryFileSync causes the library to synchronously open and re-read the file. The isbinaryfile@^4.0.8 library accepts either a file path or a Buffer, and inspects the same initial ~1000 bytes in both cases, making the Buffer overload functionally equivalent. Passing content eliminates the redundant I/O on every scanned file without changing behavior.

♻️ Proposed change
-    const isBinary = content.length > 0 && isBinaryFileSync(path);
+    const isBinary = content.length > 0 && isBinaryFileSync(content);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/sdk/scanner/WfpProvider/WfpCalculator/WfpCalculator.ts` at line 595, The
isBinary determination currently calls isBinaryFileSync(path) which causes
redundant sync file reads even though the file bytes are already loaded into the
content Buffer; update the call in the WfpCalculator (symbol: isBinary,
variables: content and path, function: isBinaryFileSync) to pass the in-memory
content Buffer instead of path so the library inspects the Buffer and avoids
re-opening the file.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/sdk/scanner/WfpProvider/WfpCalculator/WfpCalculator.ts`:
- Around line 295-320: Add unit tests covering the binary path through
wfp_for_content, wfp_hpsm_for_content, and wfp_only_md5: create a small
synthetic binary Buffer (e.g., includes a NUL byte) and call each function with
isBinary=true and a representative maxSize; assert the output contains only the
file=md5,size,path line (correct MD5 and size) and does NOT contain fh2= or any
winnowing/snippet lines produced by calc_wfp or HPSM; include separate
assertions for each function to lock the three branches and prevent regressions
like the RangeError on large binaries.
- Line 595: The isBinary determination currently calls isBinaryFileSync(path)
which causes redundant sync file reads even though the file bytes are already
loaded into the content Buffer; update the call in the WfpCalculator (symbol:
isBinary, variables: content and path, function: isBinaryFileSync) to pass the
in-memory content Buffer instead of path so the library inspects the Buffer and
avoids re-opening the file.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 982460c3-46c0-46c3-8b52-d0dcebebd76b

📥 Commits

Reviewing files that changed from the base of the PR and between 63628a4 and bdd44fd.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • package.json
  • src/sdk/scanner/Scannable/ScannableItem.ts
  • src/sdk/scanner/WfpProvider/WfpCalculator/WfpCalculator.ts

@agustingroh
agustingroh force-pushed the fix/SP-4350-skip-fh2-winnowing-HPSM-binary-files branch from bdd44fd to 48e9674 Compare April 27, 2026 18:03

@scanoss-qg scanoss-qg left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@agustingroh
agustingroh merged commit ae75223 into main Apr 28, 2026
4 checks passed
@agustingroh
agustingroh deleted the fix/SP-4350-skip-fh2-winnowing-HPSM-binary-files branch April 28, 2026 15:01
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.

3 participants