Skip to content

Commit 6013421

Browse files
authored
26.1-lcm: qcow-stream-tool: Avoid stack overflows in read_headers (#6856)
Backport of #6848
2 parents 6641f75 + 6b4f442 commit 6013421

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

ocaml/qcow-stream-tool/qcow_stream_tool.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ module Impl = struct
1212
let* virtual_size, cluster_bits, _, data_cluster_map =
1313
Qcow_stream.start_stream_decode fd
1414
in
15-
let clusters = Qcow_types.Cluster.Map.bindings data_cluster_map in
15+
(* TODO: List.map becomes tail-recursive in OCaml 5.1, and could be used here instead *)
1616
let clusters =
17-
List.map
18-
(fun (_, virt_address) ->
17+
data_cluster_map
18+
|> Qcow_types.Cluster.Map.to_seq
19+
|> Seq.map (fun (_, virt_address) ->
1920
let ( >> ) = Int64.shift_right_logical in
2021
let address =
2122
Int64.to_int (virt_address >> Int32.to_int cluster_bits)
2223
in
2324
`Int address
24-
)
25-
clusters
25+
)
26+
|> List.of_seq
2627
in
2728
let json =
2829
`Assoc

0 commit comments

Comments
 (0)