mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-07 23:17:35 -06:00
slic3r: address sanitizer cleanup in ImGuiWrapper::load_svg
ImGuiWrapper::load_svg previously could load an image that was not of the aspect ratio specified by the target_width and target_height, and as a result, could create an output vector that was smaller (or differently shaped!) than the target_width and target_height. GCC's Address Sanitizer flagged this because init_font was reading over the end of the allocated buffer, but this also meant that images with incorrect aspect ratios might get rendered to the font canvas incorrectly. To solve this, we pass the generated width and height out from load_svg, and use it when copying images later.
This commit is contained in:
parent
64173b3fa3
commit
ab64ae8c63
2 changed files with 17 additions and 11 deletions
|
@ -1636,7 +1636,7 @@ static const ImWchar ranges_keyboard_shortcuts[] =
|
|||
#endif // __APPLE__
|
||||
|
||||
|
||||
std::vector<unsigned char> ImGuiWrapper::load_svg(const std::string& bitmap_name, unsigned target_width, unsigned target_height)
|
||||
std::vector<unsigned char> ImGuiWrapper::load_svg(const std::string& bitmap_name, unsigned target_width, unsigned target_height, unsigned *outwidth, unsigned *outheight)
|
||||
{
|
||||
std::vector<unsigned char> empty_vector;
|
||||
|
||||
|
@ -1667,6 +1667,9 @@ std::vector<unsigned char> ImGuiWrapper::load_svg(const std::string& bitmap_name
|
|||
::nsvgDeleteRasterizer(rast);
|
||||
::nsvgDelete(image);
|
||||
|
||||
*outwidth = width;
|
||||
*outheight = height;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -1951,11 +1954,12 @@ void ImGuiWrapper::init_font(bool compress)
|
|||
if (const ImFontAtlas::CustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id)) {
|
||||
assert(rect->Width == icon_sz);
|
||||
assert(rect->Height == icon_sz);
|
||||
std::vector<unsigned char> raw_data = load_svg(icon.second, icon_sz, icon_sz);
|
||||
unsigned outwidth, outheight;
|
||||
std::vector<unsigned char> raw_data = load_svg(icon.second, icon_sz, icon_sz, &outwidth, &outheight);
|
||||
const ImU32* pIn = (ImU32*)raw_data.data();
|
||||
for (int y = 0; y < icon_sz; y++) {
|
||||
for (unsigned y = 0; y < outheight; y++) {
|
||||
ImU32* pOut = (ImU32*)pixels + (rect->Y + y) * width + (rect->X);
|
||||
for (int x = 0; x < icon_sz; x++)
|
||||
for (unsigned x = 0; x < outwidth; x++)
|
||||
*pOut++ = *pIn++;
|
||||
}
|
||||
}
|
||||
|
@ -1967,11 +1971,12 @@ void ImGuiWrapper::init_font(bool compress)
|
|||
if (const ImFontAtlas::CustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id)) {
|
||||
assert(rect->Width == icon_sz);
|
||||
assert(rect->Height == icon_sz);
|
||||
std::vector<unsigned char> raw_data = load_svg(icon.second, icon_sz, icon_sz);
|
||||
unsigned outwidth, outheight;
|
||||
std::vector<unsigned char> raw_data = load_svg(icon.second, icon_sz, icon_sz, &outwidth, &outheight);
|
||||
const ImU32* pIn = (ImU32*)raw_data.data();
|
||||
for (int y = 0; y < icon_sz; y++) {
|
||||
for (unsigned y = 0; y < outheight; y++) {
|
||||
ImU32* pOut = (ImU32*)pixels + (rect->Y + y) * width + (rect->X);
|
||||
for (int x = 0; x < icon_sz; x++)
|
||||
for (unsigned x = 0; x < outwidth; x++)
|
||||
*pOut++ = *pIn++;
|
||||
}
|
||||
}
|
||||
|
@ -1983,11 +1988,12 @@ void ImGuiWrapper::init_font(bool compress)
|
|||
if (const ImFontAtlas::CustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id)) {
|
||||
assert(rect->Width == icon_sz);
|
||||
assert(rect->Height == icon_sz);
|
||||
std::vector<unsigned char> raw_data = load_svg(icon.second, icon_sz, icon_sz);
|
||||
unsigned outwidth, outheight;
|
||||
std::vector<unsigned char> raw_data = load_svg(icon.second, icon_sz, icon_sz, &outwidth, &outheight);
|
||||
const ImU32* pIn = (ImU32*)raw_data.data();
|
||||
for (int y = 0; y < icon_sz; y++) {
|
||||
for (unsigned y = 0; y < outheight; y++) {
|
||||
ImU32* pOut = (ImU32*)pixels + (rect->Y + y) * width + (rect->X);
|
||||
for (int x = 0; x < icon_sz; x++)
|
||||
for (unsigned x = 0; x < outwidth; x++)
|
||||
*pOut++ = *pIn++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue