§
    2�Åj<  ã                  óð   — d Z ddlmZ ddlZddlZddlZddlZ ej        ¦   «         5  ddlm	Z	m
Z
mZmZmZmZ ddd¦  «         n# 1 swxY w Y   dZd„ Zd„ Zd„ Zd	„ Zd
„ Zd„ Zedk    r e¦   «          dS dS )aÙ  Atheris fuzz harness for onnx.compose.

Two input paths are exercised per iteration, selected by a fuzzer-controlled
toggle byte read from the *tail* of the input:

* Raw    -> a 4-byte big-endian length prefix splits the remaining bytes
  into m1 | m2, each parsed via onnx.load_model_from_string. Catches
  protobuf parser bugs and bugs reachable only through crafted serialized
  models the structured builder will not produce.

* Structured -> helper.make_model from FuzzedDataProvider builds two small
  linear graphs with predictable input/output names, so merge_models
  reaches its connect_io/add_prefix logic on most iterations rather than
  only when the parser happens to accept a random byte string.

Further bits of the toggle byte select prefix1/prefix2 (add_prefix
collision-resolution path) and a randomized (vs. derived) io_map, so a
single harness covers merge_models, merge_graphs, check_overlapping_names,
the recursive connect_io subgraph rewrite, and add_prefix.
é    )ÚannotationsN)ÚTensorProtoÚcheckerÚcomposeÚdefsÚhelperÚload_model_from_string)ÚReluÚSigmoidÚTanhÚAbsÚNegÚIdentityc                óD   — t          j        | t          j        dg¦  «        S )NÚN)r   Úmake_tensor_value_infor   ÚFLOAT©Únames    úGC:\Projects\Historical\venv\Lib\site-packages\onnx/fuzz/fuzz_compose.pyÚ_value_infor   -   s   € ÝÔ(¨­{Ô/@À3À%ÑHÔHÐHó    c                ó\  — |                       dd¦  «        }d|› �}g }t          |¦  «        D ]m}t          |                       dt          t          ¦  «        dz
  ¦  «                 }d|› d|› �}|                     t          j        ||g|g¦  «        ¦  «         |}Œnd|› �}	|                     t          j        d|g|	g¦  «        ¦  «         t          j        |d	|› �t          d|› �¦  «        gt          |	¦  «        g¦  «        }
t          j	        |
t          j
        d
|¦  «        g¬¦  «        S )a6  Build a small linear graph with predictable input/output names.

    Naming the sole input/output `In<tag>`/`Out<tag>` lets the derived
    io_map (m1's outputs -> m2's inputs) connect on most iterations, so
    merge_models' rewrite logic is reached without relying on the raw
    protobuf parser to produce compatible names. `opset` is shared between
    both models: merge_models rejects mismatched opset_import up front, so
    picking it independently per model would make the structured path
    rarely reach the merge/connect logic it exists to exercise.
    r   é   ÚIné   ÚvÚ_ÚOutr   ÚgÚ )Úopset_imports)ÚConsumeIntInRangeÚrangeÚ_UNARYÚlenÚappendr   Ú	make_nodeÚ
make_graphr   Ú
make_modelÚmake_opsetid)ÚfdpÚtagÚopsetÚn_opsÚlastÚnodesÚiÚopÚnxtÚout_nameÚgraphs              r   Ú_build_modelr7   1   s4  € ð ×!Ò! ! QÑ'Ô'€EØ�ˆ:ˆ:€DØ€EÝ�5‰\Œ\ð ð ˆÝ�C×)Ò)¨!­Sµ©[¬[¸1©_Ñ=Ô=Ô>ˆØ�#ˆmˆm˜ˆmˆmˆØ�Š•VÔ% b¨4¨&°3°%Ñ8Ô8Ñ9Ô9Ð9ØˆˆØ�Sˆ{ˆ{€HØ	‡L‚L•Ô! *¨t¨f°x°jÑAÔAÑBÔBÐBÝÔØˆy�3ˆyˆy�; z¨C z zÑ2Ô2Ð3µkÀ(Ñ6KÔ6KÐ5Lñô €Eõ Ô˜Uµ6Ô3FÀrÈ5Ñ3QÔ3QÐ2RÐSÑSÔSÐSr   c                ó˜   — d„ | j         j        D ¦   «         }d„ |j         j        D ¦   «         }t          t	          ||d¬¦  «        ¦  «        S )Nc                ó   — g | ]	}|j         ‘Œ
S © r   ©Ú.0Úos     r   ú
<listcomp>z#_derived_io_map.<locals>.<listcomp>M   ó   € Ð,Ð,Ð,�qˆAŒFÐ,Ð,Ð,r   c                ó   — g | ]	}|j         ‘Œ
S r:   r   ©r<   r2   s     r   r>   z#_derived_io_map.<locals>.<listcomp>N   ó   € Ð
*Ð
*Ð
*�aˆ1Œ6Ð
*Ð
*Ð
*r   F©Ústrict)r6   ÚoutputÚinputÚlistÚzip)Úm1Úm2ÚoutsÚinss       r   Ú_derived_io_maprM   L   sM   € Ø,Ð,˜BœHœOÐ,Ñ,Ô,€DØ
*Ð
*˜2œ8œ>Ð
*Ñ
*Ô
*€CÝ•�D˜# eÐ,Ñ,Ô,Ñ-Ô-Ð-r   c           	     ó¼  — d„ |j         j        D ¦   «         }d„ |j         j        D ¦   «         }|r|sg S t          j        | ¦  «        }|                     |¦  «         |                     |¦  «         |                     dt          t          |¦  «        t          |¦  «        ¦  «        ¦  «        }t          t          |d |…         |d |…         d¬¦  «        ¦  «        S )Nc                ó   — g | ]	}|j         ‘Œ
S r:   r   r;   s     r   r>   z"_random_io_map.<locals>.<listcomp>S   r?   r   c                ó   — g | ]	}|j         ‘Œ
S r:   r   rA   s     r   r>   z"_random_io_map.<locals>.<listcomp>T   rB   r   r   TrC   )r6   rE   rF   ÚrandomÚRandomÚshuffleÚrandintÚminr&   rG   rH   )ÚdatarI   rJ   rK   rL   ÚrngÚns          r   Ú_random_io_maprY   R   sÍ   € Ø,Ð,˜BœHœOÐ,Ñ,Ô,€DØ
*Ð
*˜2œ8œ>Ð
*Ñ
*Ô
*€CØð �sð Øˆ	Ý
Œ-˜Ñ
Ô
€CØ‡K‚K�ÑÔÐØ‡K‚K�ÑÔÐØ�Š�A•s�3˜t™9œ9¥c¨#¡h¤hÑ/Ô/Ñ0Ô0€AÝ•�D˜˜!˜”H˜c " 1 "œg¨dÐ3Ñ3Ô3Ñ4Ô4Ð4r   c                ób  — t          | ¦  «        dk     rd S | d         }| d d…         }t          |dz  ¦  «        }t          |dz  ¦  «        }t          |dz  ¦  «        }	 |r^t          j        |¦  «        }|                     dt          j        ¦   «         ¦  «        }t          |d|¦  «        }t          |d|¦  «        }	n�t          |¦  «        dk     rd S t          j	        d|d d…         ¦  «        \  }
|dd …         }|
t          |¦  «        k    rd S t          |d |
…         ¦  «        }t          ||
d …         ¦  «        }	|rt          |||	¦  «        nt          ||	¦  «        }|rdnd }|rd	nd }t          j        ||	|||¬
¦  «        }t          j        |d¬¦  «         d S # t"          $ r Y d S w xY w)Né   éÿÿÿÿr   r   é   é   z>IÚg1_Úg2_)Úprefix1Úprefix2T)Ú
full_check)r&   ÚboolÚatherisÚFuzzedDataProviderr#   r   Úonnx_opset_versionr7   ÚstructÚunpackr	   rY   rM   r   Úmerge_modelsr   Úcheck_modelÚ	Exception)rV   ÚtogglesÚbodyÚ
use_prefixÚuse_structuredÚuse_random_io_mapr,   r.   rI   rJ   Ún1ÚrestÚio_mapra   rb   Úmergeds                   r   ÚTestOneInputrv   ^   sá  € õ ˆ4�y„y�1‚}€}ØˆØ�2Œh€GØ���Œ9€DÝ�g ‘nÑ%Ô%€JÝ˜' D™.Ñ)Ô)€NÝ˜W t™^Ñ,Ô,ÐðØð 	3ÝÔ,¨TÑ2Ô2ˆCØ×)Ò)¨!­TÔ-DÑ-FÔ-FÑGÔGˆEÝ˜c 1 eÑ,Ô,ˆBÝ˜c 1 eÑ,Ô,ˆBˆBå�4‰yŒy˜1Š}ˆ}Ø�Ý”M $¨¨R¨a¨R¬Ñ1Ô1‰EˆRØ˜˜˜”8ˆDØ•C˜‘I”IŠ~ˆ~Ø�Ý'¨¨S¨b¨S¬	Ñ2Ô2ˆBÝ'¨¨R¨S¨S¬	Ñ2Ô2ˆBð !ð)�N˜4  RÑ(Ô(Ð(å   RÑ(Ô(ð 	ð &Ð/�%�%¨4ˆØ%Ð/�%�%¨4ˆÝÔ% b¨"¨f¸gÈwÐWÑWÔWˆÝÔ˜F¨tÐ4Ñ4Ô4Ð4Ð4Ð4øÝð ð ð ð 	ˆˆð	øøøs    ÁA3F  Ã<F  ÄBF  Æ 
F.Æ-F.c                 óž   — t          j        ¦   «          t          j        t          j        t
          d¬¦  «         t          j        ¦   «          d S )NT)Úenable_python_coverage)re   Úinstrument_allÚSetupÚsysÚargvrv   ÚFuzzr:   r   r   Úmainr~   Œ   s9   € ÝÔÑÔÐÝ„M•#”(�LÀÐFÑFÔFÐFÝ„L�N„N€N€N€Nr   Ú__main__)Ú__doc__Ú
__future__r   rQ   rh   r{   re   Úinstrument_importsÚonnxr   r   r   r   r   r	   r%   r   r7   rM   rY   rv   r~   Ú__name__r:   r   r   ú<module>r…      s‰  ððð ð* #Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø 
€
€
€
à €€€à€WÔÑ!Ô!ð ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð 
?€ðIð Ið IðTð Tð Tð6.ð .ð .ð	5ð 	5ð 	5ð+ð +ð +ð\ð ð ð ˆzÒÐØ€D�F„F€F€F€Fð Ðs   ¨AÁA	ÁA	