[jira] [Created] (COMPRESS-157) Wrong EOF detection in CBZip2InputStream

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (COMPRESS-157) Wrong EOF detection in CBZip2InputStream

Gilles (Jira)
Wrong EOF detection in CBZip2InputStream
----------------------------------------

                 Key: COMPRESS-157
                 URL: https://issues.apache.org/jira/browse/COMPRESS-157
             Project: Commons Compress
          Issue Type: Bug
            Reporter: Jan
            Priority: Minor


The following snippet form CBZip2InputStream does a wrong EOF check. The char 'thech' will never be equal to the integer '-1'. You have to check for #read() returning -1 before casting to char.

I found the bug in http://svn.wikimedia.org/svnroot/mediawiki/trunk/mwdumper/src/org/apache/commons/compress/bzip2/ not in your TRUNK.

{noformat}
                            int zzi;
                            char thech = 0;
                            try
                            {
                                thech = (char)m_input.read();
                            }
                            catch( IOException e )
                            {
                                compressedStreamEOF();
                            }
                            if( thech == -1 ) //HERE
                            {
                                compressedStreamEOF();
                            }
{noformat}



--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (COMPRESS-157) Wrong EOF detection in CBZip2InputStream

Gilles (Jira)

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

Sebb commented on COMPRESS-157:
-------------------------------

Are you sure the class is in Compress? I can only find BZip2CompressorInputStream which does not have the problem.

Commons VFS does have a file called CBZip2InputStream, and there is one instance of casting read() to a char:

{code}
619       while (bsLive < 1)
620       {
621           char ch = 0;
622           try
623           {
624               ch = (char) inputStream.read();
625           }
626           catch (IOException e)
627           {
628               compressedStreamEOF();
629           }
630
631           bsBuff = (bsBuff << 8) | (ch & 0xff);
632           bsLive += 8;
633       }
{code}

That does look wrong.

> Wrong EOF detection in CBZip2InputStream
> ----------------------------------------
>
>                 Key: COMPRESS-157
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-157
>             Project: Commons Compress
>          Issue Type: Bug
>            Reporter: Jan
>            Priority: Minor
>
> The following snippet form CBZip2InputStream does a wrong EOF check. The char 'thech' will never be equal to the integer '-1'. You have to check for #read() returning -1 before casting to char.
> I found the bug in http://svn.wikimedia.org/svnroot/mediawiki/trunk/mwdumper/src/org/apache/commons/compress/bzip2/ not in your TRUNK.
> {noformat}
>                             int zzi;
>                             char thech = 0;
>                             try
>                             {
>                                 thech = (char)m_input.read();
>                             }
>                             catch( IOException e )
>                             {
>                                 compressedStreamEOF();
>                             }
>                             if( thech == -1 ) //HERE
>                             {
>                                 compressedStreamEOF();
>                             }
> {noformat}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Resolved] (COMPRESS-157) Wrong EOF detection in CBZip2InputStream

Gilles (Jira)
In reply to this post by Gilles (Jira)

     [ https://issues.apache.org/jira/browse/COMPRESS-157?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Bodewig resolved COMPRESS-157.
-------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.0

The bug has been present in pre-release code of Commons Compress but it has been fixed as part of COMPRESS-29 with svn revision 732685

> Wrong EOF detection in CBZip2InputStream
> ----------------------------------------
>
>                 Key: COMPRESS-157
>                 URL: https://issues.apache.org/jira/browse/COMPRESS-157
>             Project: Commons Compress
>          Issue Type: Bug
>            Reporter: Jan
>            Priority: Minor
>             Fix For: 1.0
>
>
> The following snippet form CBZip2InputStream does a wrong EOF check. The char 'thech' will never be equal to the integer '-1'. You have to check for #read() returning -1 before casting to char.
> I found the bug in http://svn.wikimedia.org/svnroot/mediawiki/trunk/mwdumper/src/org/apache/commons/compress/bzip2/ not in your TRUNK.
> {noformat}
>                             int zzi;
>                             char thech = 0;
>                             try
>                             {
>                                 thech = (char)m_input.read();
>                             }
>                             catch( IOException e )
>                             {
>                                 compressedStreamEOF();
>                             }
>                             if( thech == -1 ) //HERE
>                             {
>                                 compressedStreamEOF();
>                             }
> {noformat}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira