From 37cee3d7ee412241d1780943ebfc9d3c1e09036a Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Fri, 28 Oct 2022 14:52:04 -0700 Subject: [PATCH 1/2] Fix qhashmd5_file for 0 nbytes input with offset value case --- src/utilities/qhash.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/utilities/qhash.c b/src/utilities/qhash.c index de55c82f..39500fcf 100644 --- a/src/utilities/qhash.c +++ b/src/utilities/qhash.c @@ -117,7 +117,7 @@ bool qhashmd5_file(const char *filepath, off_t offset, ssize_t nbytes, return false; } - // seek + // adjust the seek pointer to the offset if (offset > 0) { if (lseek(fd, offset, SEEK_SET) != offset) { close(fd); @@ -125,10 +125,9 @@ bool qhashmd5_file(const char *filepath, off_t offset, ssize_t nbytes, } } - // If we are requested to read the entire file, - // Then set nbytes to size, to properly execute the for loop below + // if requested to digest until the end of file, set nbytes to the remaining size if(nbytes == 0) { - nbytes = size; + nbytes = size - offset; } MD5_CTX context; From 13e306498a3ce58e38b6026974c319b07ef332c2 Mon Sep 17 00:00:00 2001 From: Steve Kim Date: Fri, 28 Oct 2022 15:06:35 -0700 Subject: [PATCH 2/2] code style --- src/utilities/qhash.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utilities/qhash.c b/src/utilities/qhash.c index 39500fcf..2e1d3cdc 100644 --- a/src/utilities/qhash.c +++ b/src/utilities/qhash.c @@ -117,7 +117,12 @@ bool qhashmd5_file(const char *filepath, off_t offset, ssize_t nbytes, return false; } - // adjust the seek pointer to the offset + // if requested to digest until the end of file, set nbytes to the remaining size + if(nbytes == 0) { + nbytes = size - offset; + } + + // move the seek pointer to the beginning of the offset if (offset > 0) { if (lseek(fd, offset, SEEK_SET) != offset) { close(fd); @@ -125,11 +130,6 @@ bool qhashmd5_file(const char *filepath, off_t offset, ssize_t nbytes, } } - // if requested to digest until the end of file, set nbytes to the remaining size - if(nbytes == 0) { - nbytes = size - offset; - } - MD5_CTX context; MD5Init(&context); ssize_t toread, nread;