check the return code of wxStream::Read() in wxImageHandler::DoCanRead()

and avoid reading uninitialized memory when it fails


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15601 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2002-05-18 12:41:51 +00:00
parent baaae89f09
commit 79fa23744b
9 changed files with 55 additions and 33 deletions

View File

@@ -617,10 +617,12 @@ bool wxGIFDecoder::CanRead()
{
unsigned char buf[3];
m_f->Read(buf, 3);
m_f->SeekI(-3, wxFromCurrent);
if ( !m_f->Read(buf, WXSIZEOF(buf)) )
return FALSE;
return (memcmp(buf, "GIF", 3) == 0);
m_f->SeekI(-WXSIZEOF(buf), wxFromCurrent);
return memcmp(buf, "GIF", WXSIZEOF(buf)) == 0;
}

View File

@@ -876,9 +876,13 @@ bool wxBMPHandler::DoCanRead(wxInputStream& stream)
{
unsigned char hdr[2];
stream.Read(hdr, 2);
stream.SeekI(-2, wxFromCurrent);
return (hdr[0] == 'B' && hdr[1] == 'M');
if ( !stream.Read(hdr, WXSIZEOF(hdr)) )
return FALSE;
stream.SeekI(-WXSIZEOF(hdr), wxFromCurrent);
// do we have the BMP file signature?
return hdr[0] == 'B' && hdr[1] == 'M';
}
@@ -1317,7 +1321,11 @@ bool wxANIHandler::DoCanRead(wxInputStream& stream)
}
// try to read next data chunk:
stream.Read(&FCC1, 4);
if ( !stream.Read(&FCC1, 4) )
{
// reading failed -- either EOF or IO error, bail out anyhow
return FALSE;
}
}
return FALSE;

View File

@@ -1015,7 +1015,7 @@ int wxImage::GetImageCount( const wxString &name, long type )
bool wxImage::CanRead( wxInputStream &stream )
{
wxList &list=GetHandlers();
const wxList& list = GetHandlers();
for ( wxList::Node *node = list.GetFirst(); node; node = node->GetNext() )
{

View File

@@ -230,12 +230,14 @@ int wxIFFDecoder::GetTransparentColour() const { return m_image->transparent; }
//
bool wxIFFDecoder::CanRead()
{
unsigned char buf[12] = "";
unsigned char buf[12];
m_f->Read(buf, 12);
m_f->SeekI(-12, wxFromCurrent);
if ( !m_f->Read(buf, WXSIZEOF(buf)) )
return FALSE;
return (memcmp(buf, "FORM", 4) == 0 && memcmp(buf+8, "ILBM", 4) == 0);
m_f->SeekI(-WXSIZEOF(buf), wxFromCurrent);
return (memcmp(buf, "FORM", 4) == 0) && (memcmp(buf+8, "ILBM", 4) == 0);
}

View File

@@ -378,9 +378,11 @@ bool wxJPEGHandler::DoCanRead( wxInputStream& stream )
{
unsigned char hdr[2];
stream.Read(hdr, 2);
stream.SeekI(-2, wxFromCurrent);
return (hdr[0] == 0xFF && hdr[1] == 0xD8);
if ( !stream.Read(hdr, WXSIZEOF(hdr)) )
return FALSE;
stream.SeekI(-WXSIZEOF(hdr), wxFromCurrent);
return hdr[0] == 0xFF && hdr[1] == 0xD8;
}
#endif // wxUSE_STREAMS

View File

@@ -486,13 +486,14 @@ bool wxPCXHandler::SaveFile( wxImage *image, wxOutputStream& stream, bool verbos
bool wxPCXHandler::DoCanRead( wxInputStream& stream )
{
unsigned char c;
unsigned char c = stream.GetC();
if ( !stream )
return FALSE;
c = stream.GetC();
stream.SeekI(-1, wxFromCurrent);
// not very safe, but this is all we can get from PCX header :-(
return (c == 10);
return c == 10;
}
#endif // wxUSE_STREAMS && wxUSE_PCX

View File

@@ -418,9 +418,12 @@ bool wxPNGHandler::DoCanRead( wxInputStream& stream )
{
unsigned char hdr[4];
stream.Read(hdr, 4);
stream.SeekI(-4, wxFromCurrent);
return (hdr[0] == 0x89 && hdr[1] == 'P' && hdr[2] == 'N' && hdr[3] == 'G');
if ( !stream.Read(hdr, WXSIZEOF(hdr)) )
return FALSE;
stream.SeekI(-WXSIZEOF(hdr), wxFromCurrent);
return memcmp(hdr, "\211PNG", WXSIZEOF(hdr)) == 0;
}
#endif // wxUSE_STREAMS

View File

@@ -370,11 +370,13 @@ bool wxTIFFHandler::DoCanRead( wxInputStream& stream )
{
unsigned char hdr[2];
stream.Read(&hdr, 2);
stream.SeekI(-2, wxFromCurrent);
if ( !stream.Read(&hdr, WXSIZEOF(hdr)) )
return FALSE;
return ((hdr[0] == 0x49 && hdr[1] == 0x49) ||
(hdr[0] == 0x4D && hdr[1] == 0x4D));
stream.SeekI(-WXSIZEOF(hdr), wxFromCurrent);
return (hdr[0] == 'I' && hdr[1] == 'I') ||
(hdr[0] == 'M' && hdr[1] == 'M');
}

View File

@@ -126,10 +126,12 @@ bool wxXPMDecoder::CanRead(wxInputStream& stream)
{
unsigned char buf[9];
stream.Read(buf, 9);
stream.SeekI(-9, wxFromCurrent);
if ( !stream.Read(buf, WXSIZEOF(buf)) )
return FALSE;
return (memcmp(buf, "/* XPM */", 9) == 0);
stream.SeekI(-WXSIZEOF(buf), wxFromCurrent);
return memcmp(buf, "/* XPM */", WXSIZEOF(buf)) == 0;
}
wxImage wxXPMDecoder::ReadFile(wxInputStream& stream)