From e8a733ecd746303c156a1fb3bd6564fbe74b6068 Mon Sep 17 00:00:00 2001 From: Dmitri Vereshchagin Date: Tue, 30 Jun 2026 20:53:28 +0300 Subject: [PATCH] stdlib: Fix return value of zip:zip_get/2 When a file is extracted to a directory, the function returns a map instead of a file name: 1> {ok, {_, B}} = zip:zip("", [{"F", ~""}], [memory]), ok. ok 2> {ok, H} = zip:zip_open(B, [{cwd, "/tmp"}]), zip:zip_get("F", H). {ok,#{flush => [],name => "/tmp/F"}} --- lib/stdlib/src/zip.erl | 2 +- lib/stdlib/test/zip_SUITE.erl | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/stdlib/src/zip.erl b/lib/stdlib/src/zip.erl index d27c32b8606f..d061d1f1e114 100644 --- a/lib/stdlib/src/zip.erl +++ b/lib/stdlib/src/zip.erl @@ -1784,7 +1784,7 @@ do_openzip_get(F, #openzip{files = Files, in = In0, input = Input, In1 = Input({seek, bof, Offset}, In0), case get_z_file(In1, Z, Input, Output, [], fun silent/1, CWD, ZFile, fun all/1, false, ExtraOpts) of - {file, R, _In2} -> {ok, R}; + {file, R, _In2} -> {ok, Output(flush, R)}; _ -> throw(file_not_found) end; _ -> throw(file_not_found) diff --git a/lib/stdlib/test/zip_SUITE.erl b/lib/stdlib/test/zip_SUITE.erl index 9f0967cb5fc7..e0ca0ea787dd 100644 --- a/lib/stdlib/test/zip_SUITE.erl +++ b/lib/stdlib/test/zip_SUITE.erl @@ -38,7 +38,7 @@ zip64_central_headers/1, unzip64_central_headers/1, zip64_central_directory/1, basic_timestamp/1, extended_timestamp/1, capped_timestamp/1, - uid_gid/1]). + uid_gid/1, zip_get_2_to_cwd/1]). -export([zip/5, unzip/3]). @@ -57,7 +57,8 @@ all() -> zip_options, list_dir_options, aliases, zip_api, open_leak, unzip_jar, compress_control, foldl, unzip_traversal_exploit, fd_leak, unicode, test_zip_dir, - explicit_file_info, {group, zip_group}, {group, zip64_group}]. + explicit_file_info, zip_get_2_to_cwd, + {group, zip_group}, {group, zip64_group}]. groups() -> zip_groups(). @@ -1276,6 +1277,25 @@ explicit_file_info(_Config) -> {ok, _} = zip:zip("", Files, [memory]), ok. +zip_get_2_to_cwd(Config) -> + Files = [{"file.txt", binary:copy(<<"txt">>, 100)}, + {"file.zip", binary:copy(<<"zip">>, 100)}], + CreateOpts = [memory, {uncompress, [".zip"]}], + {ok, {_, ZipBin}} = zip:zip("", Files, CreateOpts), + + PrivDir = get_value(priv_dir, Config), + {ok, ZipSrv} = zip:zip_open(ZipBin, [{cwd, PrivDir}]), + + {ok, TxtFile} = zip:zip_get("file.txt", ZipSrv), + {ok, <<"txt", _/binary>>} = file:read_file(TxtFile), + + {ok, ZipFile} = zip:zip_get("file.zip", ZipSrv), + {ok, <<"zip", _/binary>>} = file:read_file(ZipFile), + + ok = zip:zip_close(ZipSrv), + + ok. + mode(Config) -> PrivDir = get_value(pdir, Config),