Bug 1811852: Clear default DEVMODEW storage on failure, so that we try again next time. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D168110
This commit is contained in:
Bob Owen 2023-02-01 11:27:02 +00:00
Родитель bf3f183ac7
Коммит 5e2a87e682
2 изменённых файлов: 20 добавлений и 4 удалений

Просмотреть файл

@ -179,9 +179,16 @@ void nsPrintSettingsWin::InitWithInitializer(
return;
}
auto* devmode =
reinterpret_cast<const DEVMODEW*>(aSettings.mDevmodeWStorage.Elements());
if (devmode->dmSize != sizeof(DEVMODEW) ||
devmode->dmSize + devmode->dmDriverExtra >
aSettings.mDevmodeWStorage.Length()) {
return;
}
// SetDevMode copies the DEVMODE.
SetDevMode(const_cast<DEVMODEW*>(reinterpret_cast<const DEVMODEW*>(
aSettings.mDevmodeWStorage.Elements())));
SetDevMode(const_cast<DEVMODEW*>(devmode));
if (mDevMode->dmFields & DM_SCALE) {
// Since we do the scaling, grab the DEVMODE value and reset it back to 100.

Просмотреть файл

@ -324,13 +324,22 @@ nsTArray<uint8_t> nsPrinterWin::CopyDefaultDevmodeW() const {
// Allocate extra space in case of bad drivers that return a too-small
// result from DocumentProperties.
// (See https://bugzilla.mozilla.org/show_bug.cgi?id=1664530#c5)
devmodeStorageWLock->SetLength(bytesNeeded * 2);
if (!devmodeStorageWLock->SetLength(bytesNeeded * 2, fallible)) {
return devmodeStorageW;
}
memset(devmodeStorageWLock->Elements(), 0, devmodeStorageWLock->Length());
auto* devmode =
reinterpret_cast<DEVMODEW*>(devmodeStorageWLock->Elements());
LONG ret = ::DocumentPropertiesW(nullptr, autoPrinter.get(), mName.get(),
devmode, nullptr, DM_OUT_BUFFER);
MOZ_ASSERT(ret == IDOK, "DocumentPropertiesW failed");
if (ret != IDOK) {
// Make sure that the lengths in the DEVMODEW make sense.
if (ret != IDOK || devmode->dmSize != sizeof(DEVMODEW) ||
devmode->dmSize + devmode->dmDriverExtra >
devmodeStorageWLock->Length()) {
// Clear mDefaultDevmodeWStorage to make sure we try again next time.
devmodeStorageWLock->Clear();
return devmodeStorageW;
}
}