Image allocation resilience
This change is ultimately somewhat pointless, because the program may always crash on a small allocation later.
This commit is contained in:
+10
-3
@@ -17,6 +17,7 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <new>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
@@ -414,9 +415,15 @@ load_jxl(span<const uint8_t> data, const OpenContext &octx, Error *error)
|
||||
if (!setup_decoder(ctx, data, error))
|
||||
return nullptr;
|
||||
|
||||
for (bool done = false; !done;)
|
||||
if (!process_event(ctx, &done, error))
|
||||
return nullptr;
|
||||
// XXX: It might be a better idea to guard even higher.
|
||||
try {
|
||||
for (bool done = false; !done;)
|
||||
if (!process_event(ctx, &done, error))
|
||||
return nullptr;
|
||||
} catch (const bad_alloc &) {
|
||||
set_error(error, _("image allocation failure"));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
finish_box(ctx);
|
||||
attach_jxl_gain_map(ctx);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
//
|
||||
|
||||
#include "gettext.hpp"
|
||||
#include "libdn-loaders.hpp"
|
||||
#include "libdn.hpp"
|
||||
|
||||
@@ -13,6 +14,7 @@
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -77,7 +79,13 @@ ResvgRenderClosure::render(const OpenContext &ctx, double scale, Error *error)
|
||||
if (!render_dimensions(width_ * scale, height_ * scale, &uw, &uh, error))
|
||||
return nullptr;
|
||||
|
||||
vector<uint8_t> pixmap(size_t(uw) * uh * 4, 0);
|
||||
vector<uint8_t> pixmap;
|
||||
try {
|
||||
pixmap.resize(size_t(uw) * uh * 4);
|
||||
} catch (const bad_alloc &) {
|
||||
set_error(error, _("image allocation failure"));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
resvg_transform transform = resvg_transform_identity();
|
||||
transform.a = float(scale);
|
||||
|
||||
Reference in New Issue
Block a user