Hello,
it seems that the value that start to lead to wrong values is 2048M.
Also the returned hash from there is always the same as for an empty file.
I first thought it has something to do with large file support, but it
looks like that is already enabled.
(gdb) print sizeof(off_t)
$1 = 8
So I think this is caused by using default int for variable val and size.
That way the read buffer size is not determined correctly and then
STREAMReadBytes called with a negative buffer size.
int result, val, RetVal=FALSE;
...
val=FileSize;
if ((val==0) || ( val > BUFSIZ)) val=BUFSIZ;
result=STREAMReadBytes(S,Tempstr,val);
At the end it is not checked if read bytes matches the file size.
Therefore always the hash for an empty file is printed.
Attached patch modifies just as much to get a result matching
the 'sha256sum' utility.
Kind regards,
Bernhard
(gdb) bt
#0 STREAMReadBytes (S=0x5578d4d0, Buffer=0x55791560 "",
Buffsize=-2147483648) at file.c:852
#1 0xb894 in HashratHashFile (Ctx=,
Hash=0x5578d360, Type=0, Path=, FileSize=-2147483648) at
files.c:202
#2 0xbb38 in HashratHashSingleFile (Ctx=0x55789080,
HashType=, FileType=0, Path=0x7fffe1cb "../../test-2048M",
FStat=0x7fffdbe0, RetStr=0x7fffdb70) at files.c:280
#3 0xbf0e in HashItem (Ctx=0x55789080, HashType=0x5578d200
"sha512", Path=0x7fffe1cb "../../test-2048M", FStat=0x7fffdbe0,
HashStr=0x7fffdb70) at files.c:400
#4 0xbfd2 in HashratAction (Ctx=0x55789080,
Path=0x7fffe1cb "../../test-2048M", Stat=0x7fffdbe0) at files.c:436
#5 0xc55d in ProcessItem (Ctx=0x55789080, Path=0x7fffe1cb
"../../test-2048M", Stat=0x7fffdbe0) at files.c:637
#6 0xeb1f in ProcessCommandLine (Ctx=0x55789080,
argc=, argv=) at main.c:114
#7 0x7301 in main (argc=3, argv=0x7fffde68) at main.c:149
(gdb) up
#1 0xb894 in HashratHashFile (Ctx=,
Hash=0x5578d360, Type=0, Path=, FileSize=-2147483648) at
files.c:202
202 result=STREAMReadBytes(S,Tempstr,val);
(gdb) print val
$3 = -2147483648
(gdb) print FileSize
$4 = -2147483648
From e54af652164b5aec4d836d0fe9c11ba080b284c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bernhard=20=C3=9Cbelacker?=
Date: Sat, 27 May 2017 18:25:54 +0200
Subject: Avoid integer truncation on file size assignment if greater than 2G.
https://bugs.debian.org/863460
---
files.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/files.c b/files.c
index 5c6de63..840e8d2 100644
--- a/files.c
+++ b/files.c
@@ -168,7 +168,8 @@ int HashratHashFile(HashratCtx *Ctx, THash *Hash, int Type, char *Path, off_t Fi
{
STREAM *S;
char *Tempstr=NULL, *User=NULL, *Pass=NULL;
-int result, val, RetVal=FALSE;
+int result, RetVal=FALSE;
+off_t val;
off_t bytes_read=0;
switch (Type)
@@ -254,7 +255,7 @@ int HashratHashSingleFile(HashratCtx *Ctx, char *HashType, int FileType, char *P
THash *Hash;
struct stat XattrStat;
char *ptr;
-int size=0;
+off_t size=0;
*RetStr=CopyStr(*RetStr,"");
--
2.11.0