From: Ronnie Sahlberg Date: Mon, 20 Jun 2011 20:07:29 +0000 (+1000) Subject: When doping chunked multi-reads of a blob bigger than the max readsize, X-Git-Tag: upstream/1.9.6^2~391 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e4a5ba42b8212574a6c75ac518e7b3be6e619a5b;p=deb_libnfs.git When doping chunked multi-reads of a blob bigger than the max readsize, a read can sometimes span beyond the end of file. In which case individual smal read chunks beyond the end of file will return OK, 0 bytes of data and EOF==1 For this case, trap when len==0 and ignore these chunks. Do not update the read-count if / when len is 0. --- diff --git a/examples/nfsclient-sync.c b/examples/nfsclient-sync.c index 460af53..d4f6b0c 100644 --- a/examples/nfsclient-sync.c +++ b/examples/nfsclient-sync.c @@ -20,7 +20,7 @@ #define SERVER "10.1.1.27" #define EXPORT "/VIRTUAL" -#define NFSFILE "/BOOKS/Classics/Dracula.djvu" +#define NFSFILE "/BOOKS/Classics/Dracula.djvu.truncated" #define NFSFILER "/BOOKS/Classics/Dracula.djvu.renamed" #define NFSFILEW "/BOOKS/Classics/foo" #define NFSDIR "/BOOKS/Classics/" @@ -46,7 +46,7 @@ struct client { }; -char buf[2*1024*1024]; +char buf[5*1024*1024]; int main(int argc _U_, char *argv[] _U_) { diff --git a/lib/libnfs.c b/lib/libnfs.c index 905e9d8..4380653 100644 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -859,10 +859,12 @@ static void nfs_pread_mcb(struct rpc_context *rpc _U_, int status, void *command if (res->status != NFS3_OK) { rpc_set_error(nfs->rpc, "NFS: Read failed with %s(%d)", nfsstat3_to_str(res->status), nfsstat3_to_errno(res->status)); data->error = 1; - } else { - memcpy(&data->buffer[mdata->offset - data->start_offset], res->READ3res_u.resok.data.data_val, res->READ3res_u.resok.count); - if ((unsigned)data->max_offset < mdata->offset + res->READ3res_u.resok.count) { - data->max_offset = mdata->offset + res->READ3res_u.resok.count; + } else { + if (res->READ3res_u.resok.count > 0) { + memcpy(&data->buffer[mdata->offset - data->start_offset], res->READ3res_u.resok.data.data_val, res->READ3res_u.resok.count); + if ((unsigned)data->max_offset < mdata->offset + res->READ3res_u.resok.count) { + data->max_offset = mdata->offset + res->READ3res_u.resok.count; + } } } }