[ 
https://issues.apache.org/jira/browse/PDFBOX-6166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18072980#comment-18072980
 ] 

Maruan Sahyoun commented on PDFBOX-6166:
----------------------------------------

Code review with help from Claude Sonnet:

{code}
    public void rewind(int bytes) throws IOException
    {
        // check if the rewind operation is limited to the current buffer
        if (currentBufferPointer >= bytes)
        {
            currentBufferPointer -= bytes;
            position -= bytes;
        }
{code}

shouldn't we set {{isEOF = false}} here too?

{code}
    public int read(byte[] b, int offset, int length) throws IOException
    {
...
            }
            else if (!fetch())
            {
                isEOF = true;
                break;
            }
        }
        return numberOfBytesRead;
    }
{code}

if {{fetch()}} is false we return 0 - shouldn't we return -1 in this case 

{code}
    public void skip(int length) throws IOException
    {
        for (int i=0; i< length;i++)
        {
            read();
        }
    }
{code}

if we skip past EOF the loop doesn't break early as the return value is not 
being considered. 

{code}
            LOG.warn("FlateFilter: premature end of stream due to a 
DataFormatException");
{code}

wrong LOG message? we are not in FlateFilter 

{code}
    public int available() throws IOException
    {
        checkClosed();
        return is.available();
    }
{code}

Shouldn't we also add the buffers[CURRENT] bytes which have not yet been read?

{code}
    public int read(byte[] b, int offset, int length) throws IOException
{code}

>From java.io.InputStream IndexOutOfBoundsException - If off is negative, len 
>is negative, or len is greater than b.length - off. Maybe add a validation 
>right at the start of the method?

> Improve some implementation flaws in NonSeekableRandomAccessReadInputStream
> ---------------------------------------------------------------------------
>
>                 Key: PDFBOX-6166
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-6166
>             Project: PDFBox
>          Issue Type: Improvement
>          Components: IO, Parsing
>    Affects Versions: 3.0.6 PDFBox, 4.0.0
>            Reporter: Andreas Lehmkühler
>            Assignee: Andreas Lehmkühler
>            Priority: Major
>
> [~tilman] found some flaws in the implementation of 
> NonSeekableRandomAccessReadInputStream based on a posting from Daniel Gredler 
> on the users mailinglist
> As NonSeekableRandomAccessReadInputStream is backed by an InputStream we have 
> to think about the implementation of some methods as the length of the given 
> inputStream isn't available at the beginning
> * length: the current implementation relies on the internal member "size"
> * available: the current default implementation relies on length()
> * readFully: the current default implementation relies on length()



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to