Hi Vincent,

I just checked the src/osgPlugins/ive/DrawElements*.cpp files and none
of them check for an empty array before attempting to write out the
array.  I'm surprised it crashes as I would have thought trying to
write out 0 bytes from an array wouldn't require any pointers to be
dereferenced.  Still each compiler is different and catches different
bugs :-)

Attached is a modification to the src/osgPlugins/ive/DrawElements*.cpp
files.  Could you try these out.

Cheers,
Robert.

On Wed, Sep 30, 2009 at 8:27 AM, Vincent Bourdier
<[email protected]> wrote:
> Hi all,
>
> I think that it can be a good thing to tell you I just found a crash in the
> Writer in the plugin IVE.
> The crash occurs when a drawElementUInt is empty.
>
>     osg::ref_ptr<osg::DrawElementsUInt> drawelems = new
> osg::DrawElementsUInt(GL_TRIANGLES);
>
>     geom->addPrimitiveSet(drawelems.get());
>
>
>
> If there is not indexes in the DrawElementsUInt instance, the crash append
> on writing the file. I do not have time to search for a solution to solve
> the problem avoiding the crash, but if someone have some time to have a look
> on it, this can be a good thing.
>
> Thanks.
>
> Regards,
>  Vincent
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus signature
> database 4468 (20090929) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
/**********************************************************************
 *
 *    FILE:            DrawElementsUByte.cpp
 *
 *    DESCRIPTION:    Read/Write osg::DrawElementsUByte in binary format to disk.
 *
 *    CREATED BY:        Auto generated by iveGenerated
 *                    and later modified by Rune Schmidt Jensen.
 *
 *    HISTORY:        Created 20.3.2003
 *
 *    Copyright 2003 VR-C
 **********************************************************************/

#include "Exception.h"
#include "DrawElementsUByte.h"
#include "PrimitiveSet.h"

using namespace ive;

void DrawElementsUByte::write(DataOutputStream* out){
    // Write DrawElementsUByte's identification.
    out->writeInt(IVEDRAWELEMENTSUBYTE);

    // If the osg class is inherited by any other class we should also write this to file.
    osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this);
    if(prim){
        ((ive::PrimitiveSet*)(prim))->write(out);
    }
    else
        throw Exception("DrawElementsUByte::write(): Could not cast this osg::DrawElementsUByte to an osg::PrimitiveSet.");
    // Write DrawElementsUByte's properties.

    // Write array length and its elements.
    out->writeInt(size());
    if (size()!=0) out->writeCharArray((const char*)&front(), size() * CHARSIZE);
}

void DrawElementsUByte::read(DataInputStream* in){
    // Read DrawElementsUByte's identification.
    int id = in->peekInt();
    if(id == IVEDRAWELEMENTSUBYTE){
        // Code to read DrawElementsUByte's properties.
        id = in->readInt();
        // If the osg class is inherited by any other class we should also read this from file.
        osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this);
        if(prim){
            ((ive::PrimitiveSet*)(prim))->read(in);
        }
        else
            throw Exception("DrawElementsUByte::read(): Could not cast this osg::DrawElementsUByte to an osg::PrimitiveSet.");

        // Read array length and its elements.
        int size = in->readInt();
        resize(size);
        if (size!=0) in->readCharArray((char*)&front(), size * CHARSIZE);

    }
    else{
        throw Exception("DrawElementsUByte::read(): Expected DrawElementsUByte identification.");
    }
}
/**********************************************************************
 *
 *    FILE:            DrawElementsUInt.cpp
 *
 *    DESCRIPTION:    Read/Write osg::DrawElementsUInt in binary format to disk.
 *
 *    CREATED BY:        Copied from DrawElementsUShort.cpp by Marco Jez
 *                    
 *
 *    HISTORY:        Created 20.3.2003
 *
 *    Copyright 2003 VR-C
 **********************************************************************/

#include "Exception.h"
#include "DrawElementsUInt.h"
#include "PrimitiveSet.h"
#include <osg/Endian>

using namespace ive;

void DrawElementsUInt::write(DataOutputStream* out){
    // Write DrawElementsUInt's identification.
    out->writeInt(IVEDRAWELEMENTSUINT);

    // If the osg class is inherited by any other class we should also write this to file.
    osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this);
    if(prim){
        ((ive::PrimitiveSet*)(prim))->write(out);
    }
    else
        throw Exception("DrawElementsUInt::write(): Could not cast this osg::DrawElementsUInt to an osg::PrimitiveSet.");
    // Write DrawElementsUInt's properties.

    // Write array length and its elements.
    out->writeInt(size());
    if (size()!=0) out->writeCharArray((const char*)&front(), size() * INTSIZE);
}

void DrawElementsUInt::read(DataInputStream* in)
{
    // Read DrawElementsUInt's identification.
    int id = in->peekInt();
    if(id == IVEDRAWELEMENTSUINT){
        // Code to read DrawElementsUInt's properties.
        id = in->readInt();
        // If the osg class is inherited by any other class we should also read this from file.
        osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this);
        if(prim){
            ((ive::PrimitiveSet*)(prim))->read(in);
        }
        else
            throw Exception("DrawElementsUInt::read(): Could not cast this osg::DrawElementsUInt to an osg::PrimitiveSet.");

        // Read array length and its elements.
        int size = in->readInt();
        resize(size);
        if (size!=0) in->readCharArray((char*)&front(), size * INTSIZE);

        if (in->_byteswap)
        {
           for (int i = 0 ; i < size ; i++ )
           {
                osg::swapBytes4((char*)&((*this)[i])) ;
           }
        }        
    }
    else{
        throw Exception("DrawElementsUInt::read(): Expected DrawElementsUInt identification.");
    }
}
/**********************************************************************
 *
 *    FILE:            DrawElementsUShort.cpp
 *
 *    DESCRIPTION:    Read/Write osg::DrawElementsUShort in binary format to disk.
 *
 *    CREATED BY:        Auto generated by iveGenerated
 *                    and later modified by Rune Schmidt Jensen.
 *
 *    HISTORY:        Created 20.3.2003
 *
 *    Copyright 2003 VR-C
 **********************************************************************/

#include "Exception.h"
#include "DrawElementsUShort.h"
#include "PrimitiveSet.h"
#include <osg/Endian>

using namespace ive;

void DrawElementsUShort::write(DataOutputStream* out){
    // Write DrawElementsUShort's identification.
    out->writeInt(IVEDRAWELEMENTSUSHORT);

    // If the osg class is inherited by any other class we should also write this to file.
    osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this);
    if(prim){
        ((ive::PrimitiveSet*)(prim))->write(out);
    }
    else
        throw Exception("DrawElementsUShort::write(): Could not cast this osg::DrawElementsUShort to an osg::PrimitiveSet.");
    // Write DrawElementsUShort's properties.

    // Write array length and its elements.
    out->writeInt(size());
    if (size()!=0) out->writeCharArray((const char*)&front(), size() * SHORTSIZE);
}

void DrawElementsUShort::read(DataInputStream* in){
    // Read DrawElementsUShort's identification.
    int id = in->peekInt();
    if(id == IVEDRAWELEMENTSUSHORT){
        // Code to read DrawElementsUShort's properties.
        id = in->readInt();
        // If the osg class is inherited by any other class we should also read this from file.
        osg::PrimitiveSet*  prim = dynamic_cast<osg::PrimitiveSet*>(this);
        if(prim){
            ((ive::PrimitiveSet*)(prim))->read(in);
        }
        else
            throw Exception("DrawElementsUShort::read(): Could not cast this osg::DrawElementsUShort to an osg::PrimitiveSet.");

        // Read array length and its elements.
        int size = in->readInt();
        resize(size);
        in->readCharArray((char*)&front(), size * SHORTSIZE);
        
        if (in->_byteswap)
        {
           for (int i = 0 ; i < size ; i++ )
           {
              osg::swapBytes((char *)&((*this)[i]),SHORTSIZE) ;
           }
        }        
    }
    else{
        throw Exception("DrawElementsUShort::read(): Expected DrawElementsUShort identification.");
    }
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to