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

   # Which issue does this PR close?
   
   Closes #.
   
   # Rationale for this change
   
   `napi::bindgen_prelude::BigInt::get_u64` returns `(sign_bit, value, 
lossless)`, where `value` is only the lowest 64-bit word. The binding took `.1` 
and ignored the other two values, so a `BigInt` option never failed: `offset: 
-3n` was read as `3`, and `offset: 1n << 64n` was read as `0`. A caller asking 
for the wrong range got data from a different range instead of an error, which 
is harder to notice than a rejected call.
   
   The Node.js binding accepts `offset`, `size`, `gap` and `chunk` as `bigint` 
because they map to `u64`/`usize` in `opendal-core`. Those fields are the only 
place where a value outside the Rust type can be silently narrowed.
   
   # What changes are included in this PR?
   
   - `offset`, `size`, `gap` and `chunk` are converted with `bigint_to_u64` and 
`bigint_to_usize`, which reject a set sign bit and lossy values, returning 
`InvalidArg` that names the offending field.
   - `ReadOptions`, `ReaderOptions` and `WriteOptions` implement `TryFrom` 
instead of `From`, so `read`, `readSync`, `reader`, `readerSync`, `write`, 
`writeSync`, `writer` and `writerSync` return the conversion error instead of 
using a truncated value.
   - Every `BigInt` conversion in `bindings/nodejs/src` now goes through those 
helpers. Numeric `u32` options such as `concurrent`, `prefetch` and `limit` 
keep their existing N-API conversion behavior; this change covers `BigInt` 
options only.
   - `bindings/nodejs/tests/options.test.mjs` covers all eight operations with 
negative values and values at or above `2^64`, plus the valid cases `0n`, 
`offset: 3n, size: 4n`, a `u64::MAX` offset and chunked writes. These tests 
fail against the previous implementation and pass with this change.
   
   # Are there any user-facing changes?
   
   Negative `BigInt` values and values that do not fit into 64 bits now throw 
an `InvalidArg` error from the affected operation. Valid values, including 
`0n`, behave as before. `generated.d.ts` is unchanged: no public TypeScript 
signature changes.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - **Harness:** pi coding agent
   - **Model:** DeepSeek
   - **Effort:** max
   - **Role:** Reproduced the truncation against a memory backend, implemented 
the validation and the regression tests, and ran the Rust and Node.js checks. 
The reported behavior comes from the `napi` version this binding builds against 
(`BigInt::get_u64` returns the low word with a separate sign bit); the tests 
confirm that the pre-fix code accepted these values rather than rejecting them.
   


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