Pre-check
Search before asking
Apache Dubbo Component
Java SDK (apache/dubbo)
Dubbo Version
Apache Dubbo 3.3 branch, JDK 8 or later, any operating system.
Steps to reproduce this issue
Bytes.getMD5(InputStream) uses InputStream.available() as an EOF check and updates the message digest with the entire buffer instead of the number of bytes actually read.
For example, the bundled md5.testfile.txt contains only:
Calling Bytes.getMD5(File) returns the Base64 value:
The correct MD5 of hello world! is:
The same problem occurs for an InputStream whose final read is shorter than 8192 bytes.
What you expected to happen
Bytes.getMD5(InputStream) and Bytes.getMD5(File) should calculate the MD5 of exactly the bytes supplied by the input source.
Anything else
The implementation should read until read() returns -1 and update the digest with only the bytes returned by each read:
int read;
while ((read = is.read(buf)) != -1) {
md.update(buf, 0, read);
}
A pull request is prepared with tests for 12, 8191, 8192, and 8193 byte inputs, plus an input stream whose available() method returns zero while data is still readable.
Do you have a (mini) reproduction demo?
Are you willing to submit a pull request to fix on your own?
Code of Conduct
Pre-check
Search before asking
Apache Dubbo Component
Java SDK (apache/dubbo)
Dubbo Version
Apache Dubbo 3.3 branch, JDK 8 or later, any operating system.
Steps to reproduce this issue
Bytes.getMD5(InputStream)usesInputStream.available()as an EOF check and updates the message digest with the entire buffer instead of the number of bytes actually read.For example, the bundled
md5.testfile.txtcontains only:Calling
Bytes.getMD5(File)returns the Base64 value:The correct MD5 of
hello world!is:The same problem occurs for an
InputStreamwhose final read is shorter than 8192 bytes.What you expected to happen
Bytes.getMD5(InputStream)andBytes.getMD5(File)should calculate the MD5 of exactly the bytes supplied by the input source.Anything else
The implementation should read until
read()returns-1and update the digest with only the bytes returned by each read:A pull request is prepared with tests for 12, 8191, 8192, and 8193 byte inputs, plus an input stream whose
available()method returns zero while data is still readable.Do you have a (mini) reproduction demo?
Are you willing to submit a pull request to fix on your own?
Code of Conduct