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

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?

@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 59.03%. Comparing base (2d9730c) to head (b926206).

Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #16452      +/-   ##
============================================
- Coverage     61.00%   59.03%   -1.98%     
  Complexity       15       15              
============================================
  Files          1953     1953              
  Lines         89286    89286              
  Branches      13478    13478              
============================================
- Hits          54471    52706    -1765     
- Misses        29213    30868    +1655     
- Partials       5602     5712     +110     
Flag Coverage Δ
integration-tests-java21 ?
integration-tests-java8 ?
samples-tests-java21 ?
samples-tests-java8 ?
unit-tests-java11 59.27% <ø> (+0.01%) ⬆️
unit-tests-java17 58.73% <ø> (+0.02%) ⬆️
unit-tests-java21 58.69% <ø> (-0.05%) ⬇️
unit-tests-java25 58.67% <ø> (ø)
unit-tests-java8 59.26% <ø> (-0.04%) ⬇️

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.

@cuishuang

Copy link
Copy Markdown
Author

@oxsean @RainYuY Hi, Could you please review this PR at your convenience? Thank you very much.

@RainYuY

RainYuY commented Oct 20, 2026

Copy link
Copy Markdown
Member

It looks like this method isn’t used anywhere. Please fix it, mark it as deprecated, and note that it will be removed in the next version.

Signed-off-by: cuishuang <imcusg@gmail.com>
@cuishuang
cuishuang force-pushed the fix-md5-inputstream branch from c46bbd1 to b926206 Compare November 7, 2026 11:42
@cuishuang

Copy link
Copy Markdown
Author

It looks like this method isn’t used anywhere. Please fix it, mark it as deprecated, and note that it will be removed in the next version.

Thanks, @RainYuY. I rebased onto 3.3, which already includes the MD5 fix and regression tests from #16543. I marked Bytes.getMD5(File) and Bytes.getMD5(InputStream) as deprecated and documented that both will be removed in the next version. All 15 BytesTest tests passed locally.

Could you approve the new CI run and take another look when you have a chance?

This branch has not been deployed

No deployments
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