From 223f747b12f39a7859f2a3f7816ce3a33eb261d5 Mon Sep 17 00:00:00 2001 From: Phil Carns Date: Tue, 6 Aug 2024 17:08:57 -0400 Subject: [PATCH] add workaround for potential zlib-ng problem - in some cases if zlib-ng is used as the gzip library for Darshan, it will indicate that the correct number of bytes were decompressed, but will also modify some bytes in the buffer beyond that point. In the Darshan this specifically can produce a corrupted mount table by appending erroneous characters onto the string data. --- darshan-util/darshan-logutils.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/darshan-util/darshan-logutils.c b/darshan-util/darshan-logutils.c index 613d49f5d..46073c635 100644 --- a/darshan-util/darshan-logutils.c +++ b/darshan-util/darshan-logutils.c @@ -1579,6 +1579,21 @@ static int darshan_log_dzread(darshan_fd fd, int region_id, void *buf, int len) return(-1); } + /* The following is a workaround for a zlib-ng bug observed in + * https://github.com/darshan-hpc/darshan/issues/995. When zlib-ng + * 2.2.1 is used in place of the conventional zlib library, it will + * sometimes modify bytes in the buffer beyond the number of bytes + * indicated in the return code of the inflate() call. In some cases + * this results in a corrupted mount table in the Darshan parser, but + * there may be other effects as well. + * + * This workaround avoids the problem by zeroing out all trailing bytes + * in the buffer that were not supposed to have been modified by the + * decompressor. + */ + if(ret > 0 && ret < len) + memset(&((char*)(buf))[ret], 0, (len-ret)); + state->dz.prev_reg_id = region_id; return(ret); }