yan74 / afplib

JAVA Library for reading & writing AFP (Advanced Function Presentation) Files.
Apache License 2.0
37 stars 22 forks source link

AFPInputStream does not handle structured field length correctly #65

Open michaelknigge opened 2 years ago

michaelknigge commented 2 years ago

The AFPInputStream throws an AfpFormatException("premature end of file.") if the first or second byte of the structured field length is 0xFF.

If the first byte is a 0xFF the file is "broken" of course, but the second byte can be 0xFF... In my test case I have a file where a record begins with 5A1FFF

The fix is quite simple... In AFPInputStream please have a look at the method read. Just replace return header[(int) offset]; with return header[(int) offset] & 0xff;

bye, Michael