Skip to content

fix: correct MD5 calculation for InputStream and File - #16452

Open
cuishuang wants to merge 1 commit into
apache:3.3from
cuishuang:fix-md5-inputstream
Open

fix: correct MD5 calculation for InputStream and File#16452
cuishuang wants to merge 1 commit into
apache:3.3from
cuishuang:fix-md5-inputstream

Conversation

@cuishuang

Copy link
Copy Markdown

What is the purpose of the change?

Fix incorrect MD5 calculation in Bytes.getMD5(InputStream) and Bytes.getMD5(File).

The previous implementation used InputStream.available() to detect EOF and passed the entire buffer to MessageDigest.update(). For a final partial read, zero-filled bytes were included in the digest. Streams that report available() == 0 while still containing readable data were also skipped.

This change reads until read() returns -1 and updates the digest with only the bytes actually read.

GitHub issue: #16451

Checklist

  • Make sure there is a GitHub_issue field for the change.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Make sure gitHub actions can pass. Why the workflow is failing and how to fix it?

Signed-off-by: cuishuang <imcusg@gmail.com>
@codecov-commenter

codecov-commenter commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.55%. Comparing base (dab47b7) to head (c46bbd1).

Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #16452      +/-   ##
============================================
- Coverage     60.91%   60.55%   -0.37%     
- Complexity       15    10255   +10240     
============================================
  Files          1953     1953              
  Lines         89271    89265       -6     
  Branches      13473    13471       -2     
============================================
- Hits          54383    54056     -327     
- Misses        29309    29584     +275     
- Partials       5579     5625      +46     
Flag Coverage Δ
integration-tests-java21 ?
integration-tests-java8 ?
samples-tests-java21 32.16% <0.00%> (+<0.01%) ⬆️
samples-tests-java8 29.84% <0.00%> (+<0.01%) ⬆️
unit-tests-java11 59.18% <100.00%> (+0.02%) ⬆️
unit-tests-java17 58.65% <100.00%> (-0.01%) ⬇️
unit-tests-java21 58.62% <100.00%> (-0.03%) ⬇️
unit-tests-java25 58.58% <100.00%> (-0.03%) ⬇️
unit-tests-java8 59.18% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants