Xuanwo opened a new pull request, #8767:
URL: https://github.com/apache/opendal/pull/8767

   # Which issue does this PR close?
   
   None. This is a maintenance-discovered bug; the reproduction is recorded 
below.
   
   # Rationale for this change
   
   Java passes presign expiries to JNI as `Duration.toNanos()` in a signed 
`long`, and the JNI layer converted that value with `as u64`. A negative 
duration therefore became a huge unsigned nanosecond count. Against 
`origin/main`, `AsyncOperator.presignRead("report.csv", 
Duration.ofSeconds(-1))` returns a signed URL with `X-Amz-Expires` set to 
18446744072 seconds, about 584 years, instead of failing. `RetryLayer` used the 
same `as u64` conversion for `minDelay` and `maxDelay`. Durations longer than 
`Long.MAX_VALUE` nanoseconds have no valid signed representation and failed 
inside `Duration.toNanos()` with `ArithmeticException`.
   
   # What changes are included in this PR?
   
   - `AsyncOperator.presignRead`, `presignWrite`, and `presignStat` reject 
negative durations and durations longer than `Long.MAX_VALUE` nanoseconds with 
`IllegalArgumentException` before entering JNI. `Duration.ZERO` is still 
accepted, so the change does not narrow the existing OpenDAL presign contract.
   - `RetryLayer` validates `minDelay` and `maxDelay` the same way when the 
builder creates the layer.
   - The JNI entry points use `u64::try_from` instead of `as u64` and return a 
`ConfigInvalid` error, so a value that bypasses the Java check cannot wrap. 
This is defensive; Java callers see the `IllegalArgumentException` from the 
checks above.
   - Regression tests cover negative durations for all three presign operations 
with and without options, the zero and `Long.MAX_VALUE` boundaries, and invalid 
retry delays.
   
   `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`, `./mvnw 
clean compile spotless:check`, and `./mvnw verify` pass locally.
   
   # Are there any user-facing changes?
   
   Invalid presign expiries and retry delays now throw 
`IllegalArgumentException` synchronously instead of producing a presigned URL 
with a wrapped expiry, or throwing `ArithmeticException` from 
`Duration.toNanos()` for oversized values. Valid durations behave as before.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - **Pi (T3 Code)** · `magpie/group/deepseek` · `max` · Investigated the 
signed-to-unsigned duration conversions across the Java binding, implemented 
the Java and JNI validation, added regression tests, and ran local verification.


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