aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_decompress_h.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/cowboy_decompress_h.erl')
-rw-r--r--src/cowboy_decompress_h.erl29
1 files changed, 6 insertions, 23 deletions
diff --git a/src/cowboy_decompress_h.erl b/src/cowboy_decompress_h.erl
index 4e86e23..84283e5 100644
--- a/src/cowboy_decompress_h.erl
+++ b/src/cowboy_decompress_h.erl
@@ -1,5 +1,5 @@
-%% Copyright (c) 2024, jdamanalo <[email protected]>
-%% Copyright (c) 2024, Loïc Hoguin <[email protected]>
+%% Copyright (c) jdamanalo <[email protected]>
+%% Copyright (c) Loïc Hoguin <[email protected]>
%%
%% Permission to use, copy, modify, and/or distribute this software for any
%% purpose with or without fee is hereby granted, provided that the above
@@ -66,9 +66,11 @@ data(StreamID, IsFin, Data, State=#state{next=Next0, enabled=false, read_body_bu
{Commands, Next} = cowboy_stream:data(StreamID, IsFin,
buffer_to_binary([Data|Buffer]), Next0),
fold(Commands, State#state{next=Next, read_body_is_fin=IsFin});
-data(StreamID, IsFin, Data, State0=#state{next=Next0, ratio_limit=RatioLimit,
+data(StreamID, IsFin, Data0, State0=#state{next=Next0, ratio_limit=RatioLimit,
inflate=Z, is_reading=true, read_body_buffer=Buffer}) ->
- case inflate(Z, RatioLimit, buffer_to_iovec([Data|Buffer])) of
+ Data = buffer_to_iovec([Data0|Buffer]),
+ Limit = iolist_size(Data) * RatioLimit,
+ case cow_deflate:inflate(Z, Data, Limit) of
{error, ErrorType} ->
zlib:close(Z),
Status = case ErrorType of
@@ -236,22 +238,3 @@ do_build_accept_encoding([{ContentCoding, Q}|Tail], Acc0) ->
do_build_accept_encoding(Tail, Acc);
do_build_accept_encoding([], Acc) ->
Acc.
-
-inflate(Z, RatioLimit, Data) ->
- try
- {Status, Output} = zlib:safeInflate(Z, Data),
- Size = iolist_size(Output),
- do_inflate(Z, Size, iolist_size(Data) * RatioLimit, Status, [Output])
- catch
- error:data_error ->
- {error, data_error}
- end.
-
-do_inflate(_, Size, Limit, _, _) when Size > Limit ->
- {error, size_error};
-do_inflate(Z, Size0, Limit, continue, Acc) ->
- {Status, Output} = zlib:safeInflate(Z, []),
- Size = Size0 + iolist_size(Output),
- do_inflate(Z, Size, Limit, Status, [Output | Acc]);
-do_inflate(_, _, _, finished, Acc) ->
- {ok, iolist_to_binary(lists:reverse(Acc))}.