2022-02-07 09:30:52

by Chuck Lever

[permalink] [raw]
Subject: [PATCH] nfsv4.0/read: Test the behavior of reading near OFFSET_MAX

On many systems, the internal representation of a file offset or
file size is a signed 64-bit value. NFS, however, uses an unsigned
value for these quantities. The server must convert incoming offsets
and file sizes properly or risk an underflow.

Add a test which exercises this corner case.

Signed-off-by: Chuck Lever <[email protected]>
---
nfs4.0/servertests/st_read.py | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/nfs4.0/servertests/st_read.py b/nfs4.0/servertests/st_read.py
index 1b27f5d06f2f..f75b753d61c7 100644
--- a/nfs4.0/servertests/st_read.py
+++ b/nfs4.0/servertests/st_read.py
@@ -91,6 +91,18 @@ def testLargeOffset(t, env):
check(res, msg="Reading file /%s" % b'/'.join(env.opts.usefile))
_compare(t, res, b'', True)

+def testVeryLargeOffset(t, env):
+ """READ with offset far outside file
+
+ FLAGS: read all
+ DEPEND: LOOKFILE
+ CODE: RD5a
+ """
+ c = env.c1
+ res = c.read_file(env.opts.usefile, 0x7ffffffffffffffc, 10)
+ check(res, msg="Reading file /%s" % b'/'.join(env.opts.usefile))
+ _compare(t, res, b'', True)
+
def testZeroCount(t, env):
"""READ with count=0





2022-02-07 13:47:54

by J. Bruce Fields

[permalink] [raw]
Subject: Re: [PATCH] nfsv4.0/read: Test the behavior of reading near OFFSET_MAX

Applied, thanks!--b.

On Sat, Feb 05, 2022 at 12:05:29PM -0500, Chuck Lever wrote:
> On many systems, the internal representation of a file offset or
> file size is a signed 64-bit value. NFS, however, uses an unsigned
> value for these quantities. The server must convert incoming offsets
> and file sizes properly or risk an underflow.
>
> Add a test which exercises this corner case.
>
> Signed-off-by: Chuck Lever <[email protected]>
> ---
> nfs4.0/servertests/st_read.py | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/nfs4.0/servertests/st_read.py b/nfs4.0/servertests/st_read.py
> index 1b27f5d06f2f..f75b753d61c7 100644
> --- a/nfs4.0/servertests/st_read.py
> +++ b/nfs4.0/servertests/st_read.py
> @@ -91,6 +91,18 @@ def testLargeOffset(t, env):
> check(res, msg="Reading file /%s" % b'/'.join(env.opts.usefile))
> _compare(t, res, b'', True)
>
> +def testVeryLargeOffset(t, env):
> + """READ with offset far outside file
> +
> + FLAGS: read all
> + DEPEND: LOOKFILE
> + CODE: RD5a
> + """
> + c = env.c1
> + res = c.read_file(env.opts.usefile, 0x7ffffffffffffffc, 10)
> + check(res, msg="Reading file /%s" % b'/'.join(env.opts.usefile))
> + _compare(t, res, b'', True)
> +
> def testZeroCount(t, env):
> """READ with count=0
>
>