Closed jferard closed 7 years ago
@jferard Could you please provide pull requests for this?
@iryndin this commit contains the fix for this issue, but I have to remove the JRE1.6 adaptation and some IDE auto formatting.
I will provide an appropriate pull request soon.
Hello.
I can't reopen the issue, but there is still a problem. I recently read carefully the javadoc for InputStream (https://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#read(byte[]) and one can't assume that the stream has ended (end of file) if read(b)
returns less than b.length
bytes. The read operation on the stream can just block.
Therefore, the following test is not correct:
if (dbfInputStream.read(bytes) != HEADER_HALF_SIZE)
throw new IOException("The file is corrupted or is not a dbf file");
And should be replaced by:
if (readFully(dbfInputStream, bytes) != HEADER_HALF_SIZE)
throw new IOException("The file is corrupted or is not a dbf file");
Where the readFully
method returns less than bytes.length
if the end of file occured during the read operation and bytes.length
otherwise.
I'll provide a pull request as soon as possible.
There are some problems with corrupted files. Two examples : 1) Empty file a) Replace
test/resources/data1/gds_im.dbf
with an empty file of the same name b) Runmvn test
The program throws aNullPointerException
:Actually, the return value of
dbfInputStream.read(bytes)
inDbfReader.java
(line 57) is not checked. I suggest to throw anIOException
if that function returns less than the 16 expected bytes.2) Small file a) Replace test/
resources/data1/gds_im.dbf
with a file of the same name, containing 16 times the0x02
byte. b) Runmvn test
The program runs in a infinite loop. The reason is almost the same as above : inDbfMetadataUtils.readFields
, line 83, the return value ofinputStream.read(fieldBytes)
is not tested. It should returnJdbfUtils.FIELD_RECORD_LENGTH
, but it returns0
. At line 91,inputStream.read()
will then return-1
, which is different fromJdbfUtils.HEADER_TERMINATOR
, so the loop never breaks.It's not purely theoretical : I ran into those bugs with empty or corrupted files.