allthingssecurity opened a new pull request, #28540:
URL: https://github.com/apache/camel/pull/28540

   # Description
   
   [CAMEL-26047](https://issues.apache.org/jira/browse/CAMEL-26047)
   
   The minio consumer sets `CamelMinioContentLength` to the size of the object 
it read (`MinioEndpoint`, `stat.size()`). `MinioProducer.putObject` copies that 
header into the upload length, and uses the length of the body only when there 
is no header: for a `File` body and for a `byte[]`, `String`, `Path` or stream 
cache alike. A route that reads an object, changes the body (unzip, convert, 
enrich) and stores it with a minio producer therefore uploads with the old 
length. minio 9.0.3 `PartReader` reads exactly that many bytes. A longer body 
is stored cut to the old length, with no error. A shorter one fails with 
`MinioException: unexpected EOF`. This is the same problem as CAMEL-25743 in 
aws2-s3 (merged), so I fixed it the same way.
   
   Changes:
   - `MinioProducer` takes the length of the body when it is known without 
reading it (`PayloadHelper.getLength` of the body, then of its input stream). 
The content-length header (or the length of a `WrappedFile`) is used only for a 
stream whose length is not known, and the copy that computes the length stays 
as it was for a stream with neither.
   - A `java.io.File` body is uploaded with its own length (before, the header 
took precedence there too).
   - Upgrade guide (4.24), next to the aws2-s3 entry of CAMEL-25743.
   - The test-only `FakeS3Server` of the module (used by the consumer tests and 
the getObjectRange test) also answers a single part PUT and keeps the stored 
bytes.
   - No option or generated file change.
   - Backport: camel-4.23.x, 4.22.x and 4.18.x have the same code.
   
   Tests:
   - New `MinioProducerStaleContentLengthTest`, 4 tests, JUnit assertions as in 
the module. The real `MinioClient` uploads to the in-process `FakeS3Server`, 
and the test reads back what the server stored.
   - Fail on main:
     - `bodyLongerThanAStaleContentLengthHeaderIsStoredWhole`: `the whole body 
must be stored, not the length of the header ==> expected: <a body made longer 
by the route> but was: <a body mad>`.
     - `bodyShorterThanAStaleContentLengthHeaderIsStoredWithItsLength`: `a body 
shorter than the header must be stored ==> expected: <null> but was: 
<io.minio.errors.MinioException: unexpected EOF>`.
     - `fileBodyIsStoredWithItsLength`: `expected: <the content of the file> 
but was: <the>`.
   - `streamOfUnknownLengthUsesTheContentLengthHeader` is a control that passes 
on main and with the fix: a stream whose length is not known is still uploaded 
with the header length.
   - Unit tests of camel-minio with the fix: 24 run, 0 failures, 0 skipped.
   - The formatter and import-sort plugins ran. I built offline with 
`-Dasm-version=9.11` because asm 9.11.1 was not in my local repository.
   
   Related: CAMEL-25933 made the same change in camel-ibm-cos, but it did not 
change how the minio producer takes the upload length, so camel-minio still 
uploads with the stale header on main. This PR is rebased onto CAMEL-25933 (its 
range support in `FakeS3Server` is kept).
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it): 
[CAMEL-26047](https://issues.apache.org/jira/browse/CAMEL-26047).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
     (I built camel-minio and ran its tests, including the formatter and 
import-sort plugins. No generated file changes. I did not run the full root 
build.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit 
carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to