Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FuseFileSystemProvider.java - return the correct value from read method #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

NaamaGertel
Copy link

when reading from the buffer in line 296, if we got -1 it means 0 bytes were read, so we need to return 0, because this is the right value for n

when reading from the buffer in line 296, if we got -1 it means 0 bytes were read, so we need to return 0, this is the right value for n
@NaamaGertel NaamaGertel changed the title Update FuseFileSystemProvider.java Update FuseFileSystemProvider.java - return the correct value from read method Dec 25, 2018
@guss77
Copy link

guss77 commented Dec 26, 2018

I think the problem here is conflicting read() semantics: FuseFileSystemProvider.java is an adapter between POSIX semantics and Java semantics, as can be seen in the patched read() method - it implements the POSIX.1-2001 read() method by calling the SeekableByteChannel.read() method

Both POSIX and Java methods return values are the number of bytes read - if any bytes were read. The difference lies in error detection and the handling of end-of-file scenario, which the original code (before this patch) completely ignored: if the Java's read() did not return a positive number, we just return its result as the POSIX read() result.

Because POSIX read() is expected to signal end-of-file by returning 0 and an error condition by returning -1, while Java is signalling end-of-file by returning -1 and an error condition by throwing an exception (that the current FuseFileSystemProvider.java is catching and handling correctly), if an end of file is encountered on entry to FuseFileSystemProvider.read() - which happens everytime when trying to read a 0-sized file, but could also happen at other times - then read() ignores the semantic difference and causes an error to be detected by the caller, even though no error has occured and the POSIX sepecification requires it to return 0.

This patch appears to fix the problem - if no exception occured, read() must never return a negative number: if Java's read() did not return a positive number, return 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants