Skip to content
Permalink
Browse files
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 committed Aug 17, 2021
1 parent a455a51 commit ac29a5db9e403a3dcab89bd4ba0bf059828768e4
Showing with 5 additions and 4 deletions.
  1. +5 −4 external/libdxfrw/intern/dwgbuffer.cpp
@@ -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;
@@ -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 )
@@ -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

0 comments on commit ac29a5d

Please sign in to comment.