@@ -585,6 +585,159 @@ def test_subcontainer_wrong_size(
585
585
)
586
586
587
587
588
+ empty_container = Container (
589
+ name = "embedded_container_zero_container_size" ,
590
+ sections = [
591
+ Section .Code (
592
+ code = Op .PUSH1 [0 ] + Op .RJUMPI [0 ] + Op .STOP ,
593
+ max_stack_height = 1 ,
594
+ ),
595
+ Section .Container (
596
+ container = Container (
597
+ raw_bytes = ([]), # Empty subcontainer
598
+ )
599
+ ),
600
+ ],
601
+ )
602
+
603
+
604
+ @pytest .mark .parametrize (
605
+ "truncate" ,
606
+ [
607
+ (- 1 , None ),
608
+ (12 , EOFException .INCOMPLETE_SECTION_NUMBER ),
609
+ (13 , EOFException .INCOMPLETE_SECTION_NUMBER ),
610
+ (14 , EOFException .MISSING_HEADERS_TERMINATOR ),
611
+ (15 , EOFException .INCOMPLETE_SECTION_SIZE ),
612
+ (16 , EOFException .INCOMPLETE_SECTION_SIZE ),
613
+ (17 , EOFException .INCOMPLETE_SECTION_SIZE ),
614
+ (18 , EOFException .MISSING_HEADERS_TERMINATOR ),
615
+ ],
616
+ )
617
+ def test_truncated_subcontainer (eof_test , truncate ):
618
+ """Test truncated container in subcontainer header description."""
619
+ container = Container (
620
+ sections = [
621
+ Section .Code (
622
+ code = Op .RETURNCODE [0 ](0 , 0 ),
623
+ ),
624
+ stop_sub_container ,
625
+ ],
626
+ kind = ContainerKind .INITCODE ,
627
+ )
628
+ truncate_at = truncate [0 ]
629
+ truncate_error = truncate [1 ]
630
+ if truncate_at > 0 :
631
+ container = Container (
632
+ raw_bytes = container .bytecode [0 :truncate_at ],
633
+ validity_error = truncate_error ,
634
+ )
635
+ eof_test (container = container )
636
+
637
+
638
+ @pytest .mark .parametrize (
639
+ "container,exception" ,
640
+ [
641
+ pytest .param (
642
+ empty_container ,
643
+ EOFException .ZERO_SECTION_SIZE ,
644
+ ),
645
+ pytest .param (
646
+ Container (
647
+ name = "embedded_container_non_zero_section_size_zero_container_size" ,
648
+ raw_bytes = (
649
+ [
650
+ 0xEF ,
651
+ 0x00 ,
652
+ 0x01 , # Version: 1
653
+ 0x01 , # Types Length: 4
654
+ 0x00 ,
655
+ 0x04 ,
656
+ 0x02 , # Code Sections (Length: 1)
657
+ 0x00 ,
658
+ 0x01 ,
659
+ 0x00 , # Code Section 0 (Length: 6)
660
+ 0x06 ,
661
+ 0x03 , # Container Sections (Length: 1)
662
+ 0x00 ,
663
+ 0x01 ,
664
+ 0x00 , # Container Section 0 (Length: 20)
665
+ 0x00 ,
666
+ 0x00 ,
667
+ 0x14 ,
668
+ 0xFF , # Data Length: 0
669
+ 0x00 ,
670
+ 0x00 ,
671
+ 0x00 , # Terminator
672
+ # Code Section 0 types
673
+ 0x00 , # Inputs: 0
674
+ 0x80 , # Outputs: 0 (Non-returning function)
675
+ 0x00 , # Max Stack Height: 1
676
+ 0x01 ,
677
+ # Code Section 0
678
+ 0x60 , # [0] PUSH1(0)
679
+ 0x00 ,
680
+ 0xE1 , # [2] RJUMPI(0)
681
+ 0x00 ,
682
+ 0x00 ,
683
+ 0x00 , # [5] STOP
684
+ # --- Error: Invalid Container Content ---#
685
+ ]
686
+ ),
687
+ ),
688
+ EOFException .INVALID_SECTION_BODIES_SIZE ,
689
+ ),
690
+ pytest .param (
691
+ Container (
692
+ name = "embedded_container_zero_section_size" ,
693
+ raw_bytes = (
694
+ [
695
+ 0xEF ,
696
+ 0x00 ,
697
+ 0x01 , # Version: 1
698
+ 0x01 , # Types Length: 4
699
+ 0x00 ,
700
+ 0x04 ,
701
+ 0x02 , # Code Sections (Length: 1)
702
+ 0x00 ,
703
+ 0x01 ,
704
+ 0x00 , # Code Section 0 (Length: 6)
705
+ 0x06 ,
706
+ # --- Error: Invalid Container Header (zero section size) ---#
707
+ 0x03 ,
708
+ 0x00 ,
709
+ 0x00 ,
710
+ 0xFF ,
711
+ 0x00 ,
712
+ 0x00 ,
713
+ 0x00 ,
714
+ 0x00 ,
715
+ 0x80 ,
716
+ 0x00 ,
717
+ 0x01 ,
718
+ 0x60 ,
719
+ 0x00 ,
720
+ 0xE1 ,
721
+ 0x00 ,
722
+ 0x00 ,
723
+ 0x00 ,
724
+ ]
725
+ ),
726
+ ),
727
+ EOFException .ZERO_SECTION_SIZE ,
728
+ ),
729
+ ],
730
+ )
731
+ def test_subcontainer_zero_section_size (
732
+ eof_test : EOFTestFiller , container : Container , exception : EOFException
733
+ ):
734
+ """Test subcontainers with declared or non-declared zero section sizes."""
735
+ eof_test (
736
+ container = container ,
737
+ expect_exception = exception ,
738
+ )
739
+
740
+
588
741
deep_container_parametrize = pytest .mark .parametrize (
589
742
["deepest_container" , "exception" ],
590
743
[
0 commit comments