From 5c0e63458f9fa1559c35951f9f91ff67d68e4d6d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 29 Jan 2024 08:35:23 -0800 Subject: [PATCH] apprt/embedded: do not allow NaN or small content scales Fixes #1408 --- src/apprt/embedded.zig | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 511c2da36..66681df58 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -653,9 +653,15 @@ pub const Surface = struct { } pub fn updateContentScale(self: *Surface, x: f64, y: f64) void { + // We are an embedded API so the caller can send us all sorts of + // garbage. We want to make sure that the float values are valid + // and we don't want to support fractional scaling below 1. + const x_scaled = @max(1, if (std.math.isNan(x)) 1 else x); + const y_scaled = @max(1, if (std.math.isNan(y)) 1 else y); + self.content_scale = .{ - .x = @floatCast(x), - .y = @floatCast(y), + .x = @floatCast(x_scaled), + .y = @floatCast(y_scaled), }; self.core_surface.contentScaleCallback(self.content_scale) catch |err| {