Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix issue #134 #135

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,19 @@ public class SafeTensorSupport {
private static final MapType metadataTypeReference = om.getTypeFactory().constructMapType(Map.class, String.class, String.class);

public static Map<String, TensorInfo> readTensorInfoMap(ByteBuffer buf, Optional<Map<String, String>> saveMetadata) {
final long MAX_HEADER_LENGTH = 1024 * 1024 * 1024; // 1 GB
buf = buf.order(ByteOrder.LITTLE_ENDIAN);
long headerLength = buf.getLong();

// headerLength is negative
if (headerLength < 0) {
throw new IllegalArgumentException("Header length cannot be negative: " + headerLength);
}
// headerLength exceeds the maximum allowed length MAX_HEADER_LENGTH
if (headerLength > MAX_HEADER_LENGTH) {
throw new IllegalArgumentException(String.format("Header length %d exceeds the maximum allowed length %d.", headerLength, MAX_HEADER_LENGTH));
}

byte[] header = new byte[Ints.checkedCast(headerLength)];
buf.get(header);

Expand Down
Loading