"""Inspect two text fields in an original synthetic PNG; no uploads or private files. This bounded fixture exercise is not a general photo-metadata remover/parser. """ from pathlib import Path import hashlib import json import struct import zlib def chunk(kind, data): return (struct.pack('>I', len(data)) + kind + data + struct.pack('>I', zlib.crc32(kind + data) & 0xffffffff)) def read_fixture(data): assert data[:8] == b'\x89PNG\r\n\x1a\n' offset, result = 8, [] while offset < len(data): size = struct.unpack('>I', data[offset:offset + 4])[0] kind = data[offset + 4:offset + 8] payload = data[offset + 8:offset + 8 + size] crc = struct.unpack('>I', data[offset + 8 + size:offset + 12 + size])[0] assert crc == zlib.crc32(kind + payload) & 0xffffffff result.append((kind, payload)) offset += size + 12 assert offset == len(data) return result def main(): root = Path(__file__).resolve().parent # Four-by-four RGB teaching image, with deliberately fictional text. pixels = (b'\x00' + bytes([50, 100, 150]) * 4) * 4 common = [(b'IHDR', struct.pack('>IIBBBBB', 4, 4, 8, 2, 0, 0, 0)), (b'IDAT', zlib.compress(pixels)), (b'IEND', b'')] texts = [(b'tEXt', b'Author\x00Example workshop'), (b'tEXt', b'Description\x00Synthetic fixture, not a camera photo')] signature = b'\x89PNG\r\n\x1a\n' tagged = signature + b''.join(chunk(k, v) for k, v in common[:1] + texts + common[1:]) plain = signature + b''.join(chunk(k, v) for k, v in common) for name, data in [('synthetic-tagged.png', tagged), ('synthetic-without-text.png', plain)]: target = root / name if target.exists() and target.read_bytes() != data: raise SystemExit('Refusing to overwrite a different existing file: ' + str(target)) if not target.exists(): target.write_bytes(data) before_hash = hashlib.sha256(tagged).hexdigest() tagged_chunks, plain_chunks = read_fixture(tagged), read_fixture(plain) found = dict(v.decode('latin1').split('\x00', 1) for k, v in tagged_chunks if k == b'tEXt') assert found == {'Author': 'Example workshop', 'Description': 'Synthetic fixture, not a camera photo'} assert not [k for k, v in plain_chunks if k == b'tEXt'] assert [v for k, v in tagged_chunks if k == b'IDAT'] == [v for k, v in plain_chunks if k == b'IDAT'] assert hashlib.sha256((root / 'synthetic-tagged.png').read_bytes()).hexdigest() == before_hash report = {'fixture': 'original synthetic PNG, no personal data', 'dimensions': [4, 4], 'text_fields_found': found, 'plain_fixture_text_field_count': 0, 'compressed_pixel_data_equal': True, 'tagged_source_unchanged': True, 'tagged_sha256': before_hash, 'plain_sha256': hashlib.sha256(plain).hexdigest(), 'limits': 'Only PNG tEXt in these generated fixtures. No EXIF/XMP/iTXt/zTXt/JPEG/video/platform test; no anonymization or safe-upload guarantee.'} print(json.dumps(report, indent=2)) if __name__ == '__main__': main()