This repository was archived by the owner on Apr 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -485,6 +485,7 @@ let id s =
485
485
| 9 -> `ElemSection
486
486
| 10 -> `CodeSection
487
487
| 11 -> `DataSection
488
+ | 12 -> `DataCountSection
488
489
| _ -> error s (pos s) " invalid section id"
489
490
) bo
490
491
@@ -639,6 +640,12 @@ let data_section s =
639
640
section `DataSection (vec (at memory_segment)) [] s
640
641
641
642
643
+ (* DataCount section *)
644
+
645
+ let data_count_section s =
646
+ section `DataCountSection (opt vu32 true ) None s
647
+
648
+
642
649
(* Custom section *)
643
650
644
651
let custom size s =
@@ -679,13 +686,18 @@ let module_ s =
679
686
iterate custom_section s;
680
687
let elems = elem_section s in
681
688
iterate custom_section s;
689
+ let data_count = data_count_section s in
690
+ iterate custom_section s;
682
691
let func_bodies = code_section s in
683
692
iterate custom_section s;
684
693
let data = data_section s in
685
694
iterate custom_section s;
686
695
require (pos s = len s) s (len s) " junk after last section" ;
687
696
require (List. length func_types = List. length func_bodies)
688
697
s (len s) " function and code section have inconsistent lengths" ;
698
+ require
699
+ (data_count = None || data_count = Some (Int32. of_int (List. length data)))
700
+ s (len s) " data count and data section have inconsistent lengths" ;
689
701
let funcs =
690
702
List. map2 Source. (fun t f -> {f.it with ftype = t} @@ f.at)
691
703
func_types func_bodies
Original file line number Diff line number Diff line change @@ -503,6 +503,11 @@ let encode m =
503
503
let data_section data =
504
504
section 11 (vec memory_segment) data (data <> [] )
505
505
506
+ (* DataCount section *)
507
+
508
+ let data_count_section data =
509
+ section 12 len (List. length data) (data <> [] )
510
+
506
511
(* Module *)
507
512
508
513
let module_ m =
@@ -517,6 +522,7 @@ let encode m =
517
522
export_section m.it.exports;
518
523
start_section m.it.start;
519
524
elem_section m.it.elems;
525
+ data_count_section m.it.data;
520
526
code_section m.it.funcs;
521
527
data_section m.it.data
522
528
end
Original file line number Diff line number Diff line change 118
118
)
119
119
" length out of bounds"
120
120
)
121
+
122
+ (assert_malformed
123
+ (module binary
124
+ " \00 asm" " \01\00\00\00 "
125
+ " \05\03\01\00\01 " ;; memory section
126
+ " \0c\01\02 " ;; data count section (2 segments)
127
+ " \0b\06\01\00\41\00\0b\00 " ;; data section (1 segment)
128
+ )
129
+ " data count and data section have inconsistent lengths"
130
+ )
You can’t perform that action at this time.
0 commit comments