@ -65,7 +65,8 @@ void DecodedBitStreamParser::append(std::string& result, string const& in,
void DecodedBitStreamParser : : append ( std : : string & result , const char * bufIn , size_t nIn ,
void DecodedBitStreamParser : : append ( std : : string & result , const char * bufIn , size_t nIn ,
ErrorHandler & err_handler ) {
ErrorHandler & err_handler ) {
if ( err_handler . ErrCode ( ) ) return ;
// avoid null pointer exception
if ( err_handler . ErrCode ( ) | | bufIn = = nullptr ) return ;
# ifndef NO_ICONV_INSIDE
# ifndef NO_ICONV_INSIDE
if ( nIn = = 0 ) {
if ( nIn = = 0 ) {
return ;
return ;
@ -190,16 +191,20 @@ void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits_, string& res
CharacterSetECI * currentCharacterSetECI ,
CharacterSetECI * currentCharacterSetECI ,
ArrayRef < ArrayRef < char > > & byteSegments ,
ArrayRef < ArrayRef < char > > & byteSegments ,
ErrorHandler & err_handler ) {
ErrorHandler & err_handler ) {
int nBytes = count ;
BitSource & bits ( * bits_ ) ;
BitSource & bits ( * bits_ ) ;
// Don't crash trying to read more bits than we have available.
// Don't crash trying to read more bits than we have available.
int available = bits . available ( ) ;
int available = bits . available ( ) ;
// try to repair count data if count data is invalid
// try to repair count data if count data is invalid
if ( count * 8 > available ) {
if ( count * 8 > available ) {
count = ( available + 7 / 8 ) ;
count = ( available + 7 ) / 8 ;
}
}
size_t nBytes = count ;
ArrayRef < char > bytes_ ( nBytes ) ;
// issue https://github.com/opencv/opencv_contrib/issues/3478
if ( bytes_ - > empty ( ) )
return ;
ArrayRef < char > bytes_ ( count ) ;
char * readBytes = & ( * bytes_ ) [ 0 ] ;
char * readBytes = & ( * bytes_ ) [ 0 ] ;
for ( int i = 0 ; i < count ; i + + ) {
for ( int i = 0 ; i < count ; i + + ) {
// readBytes[i] = (char) bits.readBits(8);
// readBytes[i] = (char) bits.readBits(8);