Add a safety check for the buffer size in wxIDataObject

Avoid size overflow if the offset value is greater than it.
This commit is contained in:
Vadim Zeitlin
2020-08-22 23:48:58 +02:00
parent 75ad798d8b
commit 1bf76ee594

View File

@@ -745,9 +745,20 @@ STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc,
case CF_METAFILEPICT:
size = sizeof(METAFILEPICT);
break;
default:
size = ptr.GetSize();
size -= m_pDataObject->GetBufferOffset(format);
// Account for the possible offset.
const size_t
ofs = m_pDataObject->GetBufferOffset(format);
// Check that it has a reasonable value to avoid
// overflow.
if ( ofs > size )
return E_UNEXPECTED;
size -= ofs;
}
if ( !m_pDataObject->SetData(format, size, ptr.Get()) )