From 41a9ca5f2797a92a67e778048a4389783dc03a86 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 3 Sep 2014 10:45:38 +0000 Subject: [PATCH] Work around buggy printer drivers not returning correct DEVMODE size. Apparently at least one printer driver doesn't report the memory needed by its own DEVMODE struct correctly, resulting in a crash due to a buffer overflow when printing using it. Work around this by allocating slightly more memory than what we really need. Closes #16274. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@77522 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/printdlg.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/msw/printdlg.cpp b/src/msw/printdlg.cpp index 63826efb51..629df49c74 100644 --- a/src/msw/printdlg.cpp +++ b/src/msw/printdlg.cpp @@ -413,6 +413,13 @@ void wxWindowsPrintNativeData::InitializeDevMode(const wxString& printerName, Wi NULL, // these are not used. 0 ); // Zero returns buffer size. + // Some buggy printer drivers (see #16274 which claims that Kyocera + // PCL6 driver does this) seem to return a too small value from + // DocumentProperties(), resulting in a crash because when we call + // it with DM_OUT_BUFFER below, memory beyond the allocated buffer + // is overwritten. So add a bit of extra memory to work around this. + dwNeeded += 1024; + LPDEVMODE tempDevMode = static_cast( GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, dwNeeded ) ); // Step 2: