Skip to content

Commit 6ad1fdb

Browse files
committed
gguf_writer.py: _pack_val() more graular error message for array
1 parent e5ffff9 commit 6ad1fdb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

gguf-py/gguf/gguf_writer.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,14 @@ def _pack_val(self, val: Any, vtype: GGUFValueType, add_vtype: bool) -> bytes:
847847
encoded_val = val.encode("utf-8") if isinstance(val, str) else val
848848
kv_data += self._pack("Q", len(encoded_val))
849849
kv_data += encoded_val
850-
elif vtype == GGUFValueType.ARRAY and isinstance(val, Sequence) and val:
850+
elif vtype == GGUFValueType.ARRAY:
851+
852+
if not isinstance(val, Sequence):
853+
raise ValueError(f"Invalid GGUF metadata array, expecting sequence")
854+
855+
if not val:
856+
raise ValueError(f"Invalid GGUF metadata array. Empty array")
857+
851858
if isinstance(val, bytes):
852859
ltype = GGUFValueType.UINT8
853860
else:

0 commit comments

Comments
 (0)