aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/test
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2017-03-01 12:57:54 +0100
committerGitHub <[email protected]>2017-03-01 12:57:54 +0100
commita7c8804bec4d758c62f696a842cb6cb0eea97e42 (patch)
treefb9ed1f38e840c731f2f2fb6455d5fc4a2214e81 /lib/stdlib/test
parent55f203d6af5cebee168814a8f57f4b2273fa2878 (diff)
parente06dc58a9db38ad349143629f4ba7411275183ab (diff)
downloadotp-a7c8804bec4d758c62f696a842cb6cb0eea97e42.tar.gz
otp-a7c8804bec4d758c62f696a842cb6cb0eea97e42.tar.bz2
otp-a7c8804bec4d758c62f696a842cb6cb0eea97e42.zip
Merge pull request #1358 from bjorng/bjorn/stdlib/fix-zip-bugs/OTP-14189
zip: Fix bugs ERL-348 and ERL-349 OTP-14246
Diffstat (limited to 'lib/stdlib/test')
-rw-r--r--lib/stdlib/test/zip_SUITE.erl36
1 files changed, 34 insertions, 2 deletions
diff --git a/lib/stdlib/test/zip_SUITE.erl b/lib/stdlib/test/zip_SUITE.erl
index 7d90795c9e..f0feda217a 100644
--- a/lib/stdlib/test/zip_SUITE.erl
+++ b/lib/stdlib/test/zip_SUITE.erl
@@ -27,7 +27,7 @@
openzip_api/1, zip_api/1, open_leak/1, unzip_jar/1,
unzip_traversal_exploit/1,
compress_control/1,
- foldl/1]).
+ foldl/1,fd_leak/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("kernel/include/file.hrl").
@@ -40,7 +40,7 @@ all() ->
unzip_to_binary, zip_to_binary, unzip_options,
zip_options, list_dir_options, aliases, openzip_api,
zip_api, open_leak, unzip_jar, compress_control, foldl,
- unzip_traversal_exploit].
+ unzip_traversal_exploit,fd_leak].
groups() ->
[].
@@ -882,3 +882,35 @@ foldl(Config) ->
{error, enoent} = zip:foldl(ZipFun, [], File),
ok.
+
+fd_leak(Config) ->
+ ok = file:set_cwd(proplists:get_value(priv_dir, Config)),
+ DataDir = proplists:get_value(data_dir, Config),
+ Name = filename:join(DataDir, "bad_file_header.zip"),
+ BadExtract = fun() ->
+ {error,bad_file_header} = zip:extract(Name),
+ ok
+ end,
+ do_fd_leak(BadExtract, 1),
+
+ BadCreate = fun() ->
+ {error,enoent} = zip:zip("failed.zip",
+ ["none"]),
+ ok
+ end,
+ do_fd_leak(BadCreate, 1),
+
+ ok.
+
+do_fd_leak(_Bad, 10000) ->
+ ok;
+do_fd_leak(Bad, N) ->
+ try Bad() of
+ ok ->
+ do_fd_leak(Bad, N + 1)
+ catch
+ C:R ->
+ Stk = erlang:get_stacktrace(),
+ io:format("Bad error after ~p attempts\n", [N]),
+ erlang:raise(C, R, Stk)
+ end.