Invalid argument exception when trying to seek FilePosition to LONG.MAX_VALUE
Karan Mehta
k.mehta at salesforce.com
Tue Jun 4 18:31:42 UTC 2019
Thanks for your quick response. Appreciate it.
The link for man page seems a bit contradictory. At the top, it says,
"lseek() allows the file offset to be set beyond the end of the file (but
this does not change the size of the file)." but it is followed by the text
you mentioned.
The function declaration is `off_t lseek(int fd, off_t offset, int
whence);` where the offset is defined with off_t type. I was trying to
reason its size based on stackoverflow here
<https://stackoverflow.com/questions/9073667/where-to-find-the-complete-definition-of-off-t-type>.
The link
<https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html#tag_13_67>
suggests
that they would be signed integers and hence this is a potential overflow
and might result in negative value, causing it to be a reason for
exception. Should the JNI call be using this
<https://stackoverflow.com/a/14351239/4428999> instead since the Java
interface offers the option to pass long variable for the offset.
What should be the correct fix here? Of course, if the underlying OS is 32
bit, even the SO link above won't help but it would make it work on almost
all modern hardware.
On Tue, Jun 4, 2019 at 11:17 AM Alan Bateman <Alan.Bateman at oracle.com>
wrote:
> On 04/06/2019 18:13, Karan Mehta wrote:
>
> Hello everyone,
>
> Apache bookkeeper project uses Java NIO to read journal files from disk.
> Recently a change was made that would seek the file to LONG.MAX_VALUE. When
> we tried running this on a test inside a docker container with
> openjdk:8-jdk image, it results in IOException. The patch fix PR is here
> <https://github.com/apache/bookkeeper/pull/2105>. Furthermore, running it
> inside the same container on different hardware throws IOException either
> while seeking the file to LONG.MAX_VALUE or when reading the file at that
> value as per the link of the interface here
> <https://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileChannel.html#position(long)>.
> Checkout the comment here
> <https://github.com/apache/bookkeeper/pull/2105#issuecomment-497583368>.
> I am suspecting this to be a JNI related issue or bug. Let me know what you
> all think and if there's any better way to figure this out.
>
> I just checked this on macOS and Linux. macOS seems happy with lseek'ing
> to LONG.MAX_VALUE, Linux does not:
>
> [pid 34168] lseek(4, 9223372036854775807, SEEK_SET) = -1 EINVAL (Invalid
> argument)
>
> I see the man page on Linux includes "or beyond the end of a seekable
> device" in the possible reasons for EINVAL and I assume this is why it
> fails.
>
> -Alan
>
--
Karan Mehta
<http://smart.salesforce.com/sig/k.mehta//us_mb/default/link.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20190604/7036a637/attachment-0001.html>
More information about the nio-dev
mailing list