Skip to content

Commit 09acd08

Browse files
committed
fix(serialization): Check buffer size correctly in _pwrite_compat
1 parent c6a5a20 commit 09acd08

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tensorizer/serialization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3522,13 +3522,13 @@ def _mv_slice(data: "collections.abc.Buffer", s: slice):
35223522
else:
35233523

35243524
@staticmethod
3525-
def _pwrite_compat(_fd, _str, _offset, /):
3525+
def _pwrite_compat(_fd: int, _str, _offset: int, /) -> int:
35263526
# Some systems error on single I/O calls larger than the maximum
35273527
# value of a signed 32-bit integer, so limit os.pwrite calls
35283528
# to a maximum size of about one memory page less than that
35293529
MAX_LEN: typing.Final[int] = 2147479552
35303530

3531-
if len(_str) > MAX_LEN:
3531+
if TensorSerializer._buffer_size(_str) > MAX_LEN:
35323532
with TensorSerializer._mv_slice(_str, slice(MAX_LEN)) as mv:
35333533
return os.pwrite(_fd, mv, _offset)
35343534

0 commit comments

Comments
 (0)