gemini-code-assist[bot] commented on code in PR #475:
URL: https://github.com/apache/tvm-ffi/pull/475#discussion_r2850365491
##########
include/tvm/ffi/container/tensor.h:
##########
@@ -103,7 +103,8 @@ inline size_t GetDataSize(size_t numel, DLDataType dtype) {
return numel;
}
// for other sub-byte types, packing is preferred
- return (numel * dtype.bits * dtype.lanes + 7) / 8;
+ // Use uint64_t to avoid overflow on 32-bit platforms (WASM) for large
allocations.
+ return static_cast<size_t>((static_cast<uint64_t>(numel) * dtype.bits *
dtype.lanes + 7) / 8);
Review Comment:

The explicit cast of `numel` to `uint64_t` before multiplication is a
crucial and correct approach to prevent potential integer overflow on 32-bit
platforms. This directly addresses the issue of incorrect size calculations for
large tensors, which could lead to memory allocation errors or crashes.
--
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]