Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initialize return buffers in GetRawChar8 et al. (Port DWG read fix
from https://github.com/LibreCAD/libdxfrw)

From the upstream message:
GetRawChar8() would return spurious memory contents when the read
failed,leading to weird crashes later in the code.
Seen with older non-Autocad DWG files (that Autodesk DWG Trueview
however accepts with just a warning about their foreign origin)
obtained from RC model plane enthusiasts' free plans archive
aerofred.com, e.g. their "Canadair p5.dwg"

LibreCAD/libdxfrw@082409c
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Aug 4, 2021
1 parent 2ec13f6 commit b23cc4b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions external/libdxfrw/intern/dwgbuffer.cpp
Expand Up @@ -422,8 +422,8 @@ DRW_Coord dwgBuffer::get3BitDouble()
//! Reads raw char 8 bits returns a unsigned char (RC)
duint8 dwgBuffer::getRawChar8()
{
duint8 ret;
duint8 buffer;
duint8 ret = 0;
duint8 buffer = 0;
filestr->read( &buffer, 1 );
if ( bitPos == 0 )
return buffer;
Expand All @@ -439,8 +439,8 @@ duint8 dwgBuffer::getRawChar8()
//! Reads raw short 16 bits little-endian order, returns a unsigned short (RS)
duint16 dwgBuffer::getRawShort16()
{
duint8 buffer[2];
duint16 ret;
duint8 buffer[2] = {0, 0};
duint16 ret = 0;

filestr->read( buffer, 2 );
if ( bitPos == 0 )
Expand All @@ -465,6 +465,7 @@ duint16 dwgBuffer::getRawShort16()
double dwgBuffer::getRawDouble()
{
duint8 buffer[8];
memset( buffer, 0, sizeof( buffer ) );
if ( bitPos == 0 )
filestr->read( buffer, 8 );
else
Expand Down

0 comments on commit b23cc4b

Please sign in to comment.