Skip to content

Commit

Permalink
Fix overflow in sending large STDIN.
Browse files Browse the repository at this point in the history
Signed-off-by: Karolis Petrauskas <[email protected]>
  • Loading branch information
kape1395 committed Feb 20, 2025
1 parent 66b0049 commit 4a6a720
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/exec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
-endif.

-define(TIMEOUT, 30000).
-define(MAX_PACKET_SIZE, 16#FFFF - 200). % UINT16, and keep some bytes for the header (24 should be enough).

-record(state, {
port,
Expand Down Expand Up @@ -559,6 +560,10 @@ pid(OsPid) when is_integer(OsPid) ->
%% @end
%%-------------------------------------------------------------------------
-spec send(OsPid :: ospid() | pid(), binary() | 'eof') -> ok.
send(OsPid, <<Chunk:(?MAX_PACKET_SIZE)/binary, Tail/binary>>)
when Tail =/= <<>> ->
ok = send(OsPid, Chunk),
send(OsPid, Tail);
send(OsPid, Data)
when (is_integer(OsPid) orelse is_pid(OsPid)),
(is_binary(Data) orelse Data =:= eof) ->
Expand Down

0 comments on commit 4a6a720

Please sign in to comment.