5041655: (ch) FileLock: negative param and overflow issues

Reviewed-by: alanb
This commit is contained in:
Brian Burkhalter 2022-02-22 17:24:15 +00:00
parent 7feabee426
commit 6445ee46b5
9 changed files with 247 additions and 45 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1271,6 +1271,8 @@ public class FileChannelImpl
throw new NonReadableChannelException();
if (!shared && !writable)
throw new NonWritableChannelException();
if (size == 0)
size = Long.MAX_VALUE - Math.max(0, position);
FileLockImpl fli = new FileLockImpl(this, position, size, shared);
FileLockTable flt = fileLockTable();
flt.add(fli);
@ -1316,6 +1318,8 @@ public class FileChannelImpl
throw new NonReadableChannelException();
if (!shared && !writable)
throw new NonWritableChannelException();
if (size == 0)
size = Long.MAX_VALUE - Math.max(0, position);
FileLockImpl fli = new FileLockImpl(this, position, size, shared);
FileLockTable flt = fileLockTable();
flt.add(fli);