zlib inflate function bug

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
User avatar
n9ine
Halfling
Posts: 55
Joined: Mon Aug 25, 2008 4:24 pm

zlib inflate function bug

Post by n9ine » Wed Feb 10, 2010 10:07 am

Hi all;

after adding 2500 zip file into my resource location Ogre crash and after inspecting the problem i found that zlib inflate function has a bug.
This bug is known on internet and I can not find a patch for that.
Can some one help me how to solve this problem.

here is zzip_file_read used by ogremain to load a ressource from zip file.

Code: Select all

zzip_ssize_t
zzip_file_read(ZZIP_FILE * fp, void *buf, zzip_size_t len)
{
    ZZIP_DIR *dir;
    zzip_size_t l;
    zzip_ssize_t rv;

    if (! fp || ! fp->dir)
        return 0;

    dir = fp->dir;
    l = fp->restlen > len ? len : fp->restlen;
	printf("len = %d\n",fp->restlen);
	if(l > 10000000)
		l=10000000;
    if (fp->restlen == 0)
        return 0;

    /*
     * If this is other handle than previous, save current seek pointer
     * and read the file position of `this' handle.
     */
    if (dir->currentfp != fp)
    {
        if (zzip_file_saveoffset(dir->currentfp) < 0
            || fp->io->fd.seeks(dir->fd, fp->offset, SEEK_SET) < 0)
            { dir->errcode = ZZIP_DIR_SEEK; return -1; }
        else
            { dir->currentfp = fp; }
    }

    /* if more methods is to be supported, change this to `switch ()' */
    if (fp->method)             /* method != 0   == 8, inflate */
    {
        fp->d_stream.avail_out = l;
        fp->d_stream.next_out = (unsigned char *) buf;

        do
        {
            int err;
            zzip_size_t startlen;

            if (fp->crestlen > 0 && fp->d_stream.avail_in == 0)
            {
                zzip_size_t cl = (fp->crestlen < ZZIP_32K ?
                                  fp->crestlen : ZZIP_32K);
                /*  zzip_size_t cl =
                 *      fp->crestlen > 128 ? 128 : fp->crestlen;
                 */
                zzip_ssize_t i = fp->io->fd.read(dir->fd, fp->buf32k, cl);

                if (i <= 0)
                {
                    dir->errcode = ZZIP_DIR_READ;
                    /* or ZZIP_DIR_READ_EOF ? */
                    return -1;
                }
                fp->crestlen -= i;
                fp->d_stream.avail_in = i;
                fp->d_stream.next_in = (unsigned char *) fp->buf32k;
            }

            startlen = fp->d_stream.total_out;
            err = inflate(&fp->d_stream,Z_NO_FLUSH); 

            if (err == Z_STREAM_END)
                { fp->restlen = 0; }
            else if (err == Z_OK)
                { fp->restlen -= (fp->d_stream.total_out - startlen); }
            else
               { dir->errcode = err; return -1; }
        }
        while (fp->restlen && fp->d_stream.avail_out);

        return l - fp->d_stream.avail_out;
    } else
    {                           /* method == 0 -- unstore */
        rv = fp->io->fd.read(dir->fd, buf, l);
        if (rv > 0)
            { fp->restlen-= rv; }
        else if (rv < 0)
            { dir->errcode = ZZIP_DIR_READ; }
        return rv;
    }
}
for the first files say(1..2499) every this is ok and inflate function returns Z_OK but after that zzip_file_read return -1.
My zip files are not corrupted or big sized.

Code: Select all

           
 startlen = fp->d_stream.total_out;
            err = inflate(&fp->d_stream,Z_NO_FLUSH);  

 if (err == Z_STREAM_END)
                { fp->restlen = 0; }
            else if (err == Z_OK)
                { fp->restlen -= (fp->d_stream.total_out - startlen); }
            else
               { dir->errcode = err; return -1; }
Is it possible to solve that inside OgreZip class?
0 x

User avatar
n9ine
Halfling
Posts: 55
Joined: Mon Aug 25, 2008 4:24 pm

Re: zlib inflate function bug

Post by n9ine » Fri Feb 12, 2010 6:00 pm

I decided to implement 7ZipArchive Plugin !
0 x

Post Reply