professor-moody opened a new pull request, #19997: URL: https://github.com/apache/tvm/pull/19997
### Motivation `TensorCacheMetadata::FileRecord::ParamRecord::Load` copies each parameter out of the shard buffer using `byte_offset` and `nbytes` read from `tensor-cache.json`. `FileRecord::Load` validates only the shard total (`TVM_FFI_CHECK_EQ(this->nbytes, raw_data_buffer->length())`), not each parameter's range, so a cache directory whose per-parameter `byteOffset`/`nbytes` are inconsistent with the shard reads out of bounds of the shard buffer (both the `f32-to-bf16` `memcpy` path and the `CopyTensorFromBytes` path). Bounds-checking the file-controlled offsets before the copy is cheap, self-documenting defensive hardening: it turns a hard-to-debug out-of-bounds read into a clear, actionable error when a cache directory is truncated or inconsistent. ### Change Add an overflow-safe bounds check at the top of `ParamRecord::Load`, raising `ValueError` (matching the existing `TVM_FFI_CHECK_EQ` shard-total check in `FileRecord::Load`) with the offending range: - `byte_offset >= 0 && nbytes >= 0 && byte_offset <= shard_len && nbytes <= shard_len - byte_offset` The condition is written as `nbytes <= shard_len - byte_offset` (rather than `byte_offset + nbytes <= shard_len`) to avoid signed overflow. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
