[erlang-patches] Re: [PATCH] file: fix hang reading compressed files

Henrik Nord henrik@REDACTED
Thu Apr 7 15:17:43 CEST 2011


On 04/07/2011 02:41 PM, Michael Santos wrote:
> The gzio driver goes into an infinite loop when reading past the end of
> a compressed file.
>
> Reported-By: Alex Morarash
> ---
>   erts/emulator/drivers/common/gzio.c |    2 ++
>   lib/kernel/test/file_SUITE.erl      |    4 ++++
>   2 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/erts/emulator/drivers/common/gzio.c b/erts/emulator/drivers/common/gzio.c
> index 5531a27..418b1b0 100644
> --- a/erts/emulator/drivers/common/gzio.c
> +++ b/erts/emulator/drivers/common/gzio.c
> @@ -632,6 +632,7 @@ erts_gzseek(gzFile file, int offset, int whence)
>       while (s->position<  pos) {
>   	char buf[512];
>   	int n;
> +	int save_pos = s->position;
>
>   	n = pos - s->position;
>   	if (n>  sizeof(buf))
> @@ -643,6 +644,7 @@ erts_gzseek(gzFile file, int offset, int whence)
>   	    memset(buf, '\0', n);
>   	    erts_gzwrite(file, buf, n);
>   	}
> +	if (save_pos == s->position) break;
>       }
>
>       return s->position;
> diff --git a/lib/kernel/test/file_SUITE.erl b/lib/kernel/test/file_SUITE.erl
> index 47592dd..2ad8880 100644
> --- a/lib/kernel/test/file_SUITE.erl
> +++ b/lib/kernel/test/file_SUITE.erl
> @@ -2041,6 +2041,10 @@ try_read_file_list(Fd) ->
>       ?line Title = "Real Programmers Don't Use PASCAL</TITLE>\n",
>       ?line Title = io:get_line(Fd, ''),
>
> +    %% Seek past the end of the file.
> +
> +    ?line {ok, _} = ?FILE_MODULE:position(Fd, 25000),
> +
>       %% Done.
>
>       ?line ?FILE_MODULE:close(Fd),
>    
Thanks
Refetched

-- 
/Henrik Nord Erlang/OTP




More information about the erlang-patches mailing list