Skip to content

Vector subscript out of bounds when writing zero bytes #70

@phmkopp

Description

@phmkopp

The following function accesses data[0] regardless of its size, so also if there are no bytes to write. This directly fails when bounds checking is enabled, but is otherwise UB and may lead to correct results since writing zero bytes of an invalid address can still work as expected.

template<typename T>
inline void RawBinaryAppendedWriter::writeData( std::ostream&,
                                                const std::vector<T>& data )
{
  HeaderType rawBytes = data.size( ) * sizeof( T );

  appendedData.emplace_back( reinterpret_cast<const char*>( &data[0] ), rawBytes );

  offset += sizeof( HeaderType ) + rawBytes;
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions