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

   # Which issue does this PR close?
   
   None. Found during maintenance; no separate issue was filed.
   
   # Rationale for this change
   
   N-API truncates fractional numbers and wraps out-of-range ones when it 
converts a JavaScript number to a fixed-width integer, and the binding cast the 
result again without checking it. Invalid input therefore changed the operation 
instead of failing:
   
   - `TimeoutLayer.timeout` and `ioTimeout` turned negative, `NaN`, and 
sub-millisecond values into `Duration::ZERO`, so every operation timed out 
immediately, and `Infinity` became a deadline 584 million years away.
   - `RetryLayer.maxTimes` wrapped `-1` to 4294967295 retries, truncated `1.5` 
to `1`, and wrapped `2 ** 32` to no retries at all.
   - `RetryLayer.factor` accepted `NaN`, values below `1.0`, and values wider 
than an `f32`, which make the backoff shrink or overflow.
   - `RetryLayer.minDelay` and `maxDelay` clamped negative values and `NaN` to 
zero.
   - `ThrottleLayer` wrapped a negative bandwidth to 4294967295 B/s, which 
effectively disables throttling, and truncated a fractional one.
   - `concurrent`, `chunk`, `prefetch`, and `limit` of the read, reader, write, 
and list options wrapped `-1` to 4294967295 and truncated fractions.
   - `expires` of the four presign calls wrapped a negative value into a 
request that stays valid for more than a century.
   
   # What changes are included in this PR?
   
   `bindings/nodejs/src/validate.rs`
   
   - `parse_count` converts a `f64` into an integer within `min..=u32::MAX` and 
rejects fractions, negatives, `NaN`, `Infinity`, and larger values with 
`Status::InvalidArg`. It replaces the per-site casts and the narrower 
`parse_permits` helper from #8867.
   - `parse_millis` converts milliseconds with `Duration::try_from_secs_f64`, 
so negative, non-finite, and unrepresentable values are rejected instead of 
becoming a zero or saturated duration. Sub-millisecond values keep their 
precision.
   - `parse_timeout_millis` additionally rejects a duration that is zero, 
including values that round down to zero.
   - `parse_expires_secs` validates the presign `expires` argument.
   
   `bindings/nodejs/src/layer.rs`
   
   - `RetryLayer` stores `usize`, `f32`, and `Duration` values validated by the 
setters, and `build()` no longer casts.
   - `TimeoutLayer` stores `Duration` values validated by the setters.
   - `ConcurrentLimitLayer` and `ThrottleLayer` take `f64` arguments and 
validate them in the constructor and the setter.
   
   `bindings/nodejs/src/options.rs`
   
   - `ReadOptions`, `ReaderOptions`, `WriteOptions`, and `ListOptions` declare 
their count fields as `Option<f64>` and validate them in the conversion.
   - `ListOptions` converts with `TryFrom` instead of `From`; `lib.rs` 
propagates the error from `list`, `listSync`, `lister`, and `listerSync`.
   
   `bindings/nodejs/src/lib.rs`
   
   - The four presign calls validate `expires`.
   - `Reader.readChunk` reuses `parse_count`, which keeps its existing range 
and message.
   
   Tests
   
   - `tests/layer.test.mjs` covers `ThrottleLayer`, `ConcurrentLimitLayer`, 
`RetryLayer`, and `TimeoutLayer` with negative, `NaN`, `Infinity`, fractional, 
and out-of-range values, plus the accepted boundaries: zero `maxTimes` and 
delays, the largest bandwidth and burst, and factors up to `f32::MAX`.
   - `tests/options.test.mjs` covers read, reader, write, and list counts with 
the same values, plus zero and positive values on the `memory` service, and the 
presign `expires` argument.
   
   Reverting only `bindings/nodejs/src/` to the parent commit and rebuilding 
the addon makes 48 of the 75 layer tests and 110 of the 177 option tests fail. 
With this change all 252 pass, and the full suite passes with 
`OPENDAL_TEST=memory`.
   
   # Are there any user-facing changes?
   
   Invalid numbers now raise `InvalidArg` when the layer or the operation is 
configured, instead of being silently truncated or wrapped. Valid input behaves 
as before.
   
   The accepted count range is 0 to 4294967295 for the option fields, 1 to 
4294967295 for `permits`, `httpPermits`, `bandwidth`, `burst`, and `expires`, 
and 0 to 4294967295 for `maxTimes`, where 0 disables retries. `permits` 
previously accepted any value up to `usize::MAX`; it now shares the count 
range, which no practical limit can reach. A zero `timeout` or `ioTimeout` is 
rejected because it would time out every operation. Fractional milliseconds are 
kept as sub-millisecond durations instead of being truncated.
   
   `generated.d.ts` changes in doc comments only: the signatures stay `number`, 
including the `string`-argument-free presign calls, so no TypeScript code needs 
to change.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi (T3 Code)
   - Model: DeepSeek
   - Effort: Max
   - Role: Located the unvalidated conversions, wrote the Rust and JavaScript 
changes and the tests, reproduced the failures on the parent commit, and ran 
local verification. The human author remains responsible for every claim here. 
The `memory` service ignores `limit`, does not implement conditional reads, and 
does not support presigning, so those positive cases only prove that the 
binding forwards valid values; they do not exercise service-side behavior.
   


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