Skip to content

Commit 37de895

Browse files
committed
Drain any remaining body bytes with open archive
Signed-off-by: Changlei Li <changlei.li@citrix.com>
1 parent b59864f commit 37de895

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

ocaml/xapi/import.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,6 +2452,28 @@ let metadata_handler (req : Request.t) s _ =
24522452
debug "Got XML" ;
24532453
(* Skip trailing two zero blocks *)
24542454
Tar_helpers.skip s (Tar.Header.length * 2) ;
2455+
(* Drain any remaining body bytes (e.g. tar RECORDSIZE padding)
2456+
to prevent EPIPE on the client. See CA-426637. *)
2457+
Option.iter
2458+
(fun content_length ->
2459+
let file_size = String.length metadata in
2460+
let zero_pad =
2461+
(Tar.Header.length - (file_size mod Tar.Header.length))
2462+
mod Tar.Header.length
2463+
in
2464+
let consumed =
2465+
Tar.Header.length + file_size + zero_pad
2466+
+ (Tar.Header.length * 2)
2467+
in
2468+
let remaining = Int64.to_int content_length - consumed in
2469+
if remaining > 0 then (
2470+
debug "Draining %d remaining body bytes" remaining ;
2471+
(try Tar_helpers.skip s remaining
2472+
with End_of_file -> ()
2473+
)
2474+
)
2475+
)
2476+
req.Request.content_length ;
24552477
let header = metadata |> Xmlrpc.of_string |> header_of_rpc in
24562478
assert_compatible ~__context header.version ;
24572479
if full_restore then

0 commit comments

Comments
 (0)