Clipboard: Remove-unused bpp metadata

It's just more attack surface, and can be deduced from the format anyway.
This commit is contained in:
Ben Wiederhake 2020-12-05 20:24:27 +01:00 committed by Andreas Kling
parent 4427da989f
commit 6c2ea4c4e9
2 changed files with 24 additions and 2 deletions

View file

@ -161,7 +161,6 @@ void Clipboard::set_bitmap(const Gfx::Bitmap& bitmap)
metadata.set("height", String::number(bitmap.height()));
metadata.set("format", String::number((int)bitmap.format()));
metadata.set("pitch", String::number(bitmap.pitch()));
metadata.set("bpp", String::number(bitmap.bpp()));
set_data({ bitmap.scanline(0), bitmap.size_in_bytes() }, "image/x-serenityos", metadata);
}

View file

@ -51,6 +51,29 @@ String ClipboardHistoryModel::column_name(int column) const
}
}
static const char* bpp_for_format_resilient(String format)
{
unsigned format_uint = format.to_uint().value_or(static_cast<unsigned>(Gfx::BitmapFormat::Invalid));
// Cannot use Gfx::Bitmap::bpp_for_format here, as we have to accept invalid enum values.
switch (static_cast<Gfx::BitmapFormat>(format_uint)) {
case Gfx::BitmapFormat::Indexed1:
return "1";
case Gfx::BitmapFormat::Indexed2:
return "2";
case Gfx::BitmapFormat::Indexed4:
return "4";
case Gfx::BitmapFormat::Indexed8:
return "8";
case Gfx::BitmapFormat::RGB32:
case Gfx::BitmapFormat::RGBA32:
return "32";
case Gfx::BitmapFormat::Invalid:
/* fall-through */
default:
return "?";
}
}
GUI::Variant ClipboardHistoryModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
{
if (role != GUI::ModelRole::Display)
@ -67,7 +90,7 @@ GUI::Variant ClipboardHistoryModel::data(const GUI::ModelIndex& index, GUI::Mode
builder.append('x');
builder.append(data_and_type.metadata.get("height").value_or("?"));
builder.append('x');
builder.append(data_and_type.metadata.get("bpp").value_or("?"));
builder.append(bpp_for_format_resilient(data_and_type.metadata.get("height").value_or("0")));
builder.append(" bitmap");
builder.append("]");
return builder.to_string();