Skip to content

Commit

Permalink
Merge pull request #135 from c2an1/fix-issue-#134
Browse files Browse the repository at this point in the history
Fix issue #134
  • Loading branch information
tjake authored Dec 27, 2024
2 parents 6da3b7d + 6c0329e commit a496949
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit a496949

Please sign in to comment.