From eff73bad760c860d3b3ab0908d332bd6100c60c8 Mon Sep 17 00:00:00 2001 From: Riccardo Corsi Date: Wed, 14 Jun 2017 16:09:40 +0200 Subject: [PATCH] BinaryStreamOperator: read and write block size as long long integer on 8 bytes, to accommodate arbitrarily large block size. When reading check of file version for backward compatibility. --- src/osgPlugins/osg/BinaryStreamOperator.h | 31 ++++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/osgPlugins/osg/BinaryStreamOperator.h b/src/osgPlugins/osg/BinaryStreamOperator.h index 552bb10ff..fd4453234 100644 --- a/src/osgPlugins/osg/BinaryStreamOperator.h +++ b/src/osgPlugins/osg/BinaryStreamOperator.h @@ -90,9 +90,9 @@ public: { if ( mark._name=="{" ) { - int size = 0; + long long size = 0; _beginPositions.push_back( _out->tellp() ); - _out->write( (char*)&size, osgDB::INT_SIZE ); + _out->write( (char*)&size, osgDB::INT64_SIZE ); } else if ( mark._name=="}" && _beginPositions.size()>0 ) { @@ -101,8 +101,8 @@ public: _out->seekp( beginPos ); std::streampos size64 = pos - beginPos; - int size = (int) size64; - _out->write( (char*)&size, osgDB::INT_SIZE ); + long long size = (long long) size64; + _out->write( (char*)&size, osgDB::INT64_SIZE); _out->seekp( pos ); } } @@ -244,12 +244,25 @@ public: { if ( mark._name=="{" ) { - int size = 0; _beginPositions.push_back( _in->tellg() ); - _in->read( (char*)&size, osgDB::INT_SIZE ); - if ( _byteSwap ) osg::swapBytes( (char*)&size, osgDB::INT_SIZE ); - _blockSizes.push_back( size ); + // since version 149 (osg version > 3.5.6) size is expressed + // on 8 bytes rather than 4 bytes, + // to accommodate any block size. + if (getInputStream() && getInputStream()->getFileVersion() > 148) + { + long long size = 0; + _in->read( (char*)&size, osgDB::INT64_SIZE); + if ( _byteSwap ) osg::swapBytes( (char*)&size, osgDB::INT64_SIZE); + _blockSizes.push_back( size ); + } + else + { + int size = 0; + _in->read( (char*)&size, osgDB::INT_SIZE); + if ( _byteSwap ) osg::swapBytes( (char*)&size, osgDB::INT_SIZE); + _blockSizes.push_back( size ); + } } else if ( mark._name=="}" && _beginPositions.size()>0 ) { @@ -279,7 +292,7 @@ public: protected: std::vector _beginPositions; - std::vector _blockSizes; + std::vector _blockSizes; }; #endif