font/sprite: bounds checking for pixel writes on Pixman

This commit is contained in:
Mitchell Hashimoto
2024-09-29 09:33:28 -07:00
parent e47e7a8b8b
commit f67a647a12
2 changed files with 13 additions and 5 deletions

View File

@ -409,6 +409,11 @@ const PixmanImpl = struct {
/// Draw and fill a single pixel
pub fn pixel(self: *Canvas, x: u32, y: u32, color: Color) void {
if (comptime std.debug.runtime_safety) {
assert(x < self.image.getWidth());
assert(y < self.image.getHeight());
}
const boxes = &[_]pixman.Box32{
.{
.x1 = @intCast(x),
@ -433,10 +438,13 @@ const PixmanImpl = struct {
},
};
assert(boxes[0].x1 >= 0);
assert(boxes[0].y1 >= 0);
assert(boxes[0].x2 <= @as(i32, @intCast(self.image.getWidth())));
assert(boxes[0].y2 <= @as(i32, @intCast(self.image.getHeight())));
if (comptime std.debug.runtime_safety) {
assert(boxes[0].x1 >= 0);
assert(boxes[0].y1 >= 0);
assert(boxes[0].x2 <= @as(i32, @intCast(self.image.getWidth())));
assert(boxes[0].y2 <= @as(i32, @intCast(self.image.getHeight())));
}
self.image.fillBoxes(.src, color.pixmanColor(), boxes) catch {};
}

View File

@ -27,7 +27,7 @@ pub fn renderGlyph(
line_pos: u32,
line_thickness: u32,
) !font.Glyph {
// Draw the appropriate sprite
// Draw the appropriate sprite
var canvas: font.sprite.Canvas, const offset_y: i32 = switch (sprite) {
.underline => try drawSingle(alloc, width, line_thickness),
.underline_double => try drawDouble(alloc, width, line_thickness),