summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 16:13:35 -0300
committerGabriel Schneider <[email protected]>2026-11-23 16:28:34 -0300
commit60c428d74f8aad24d002a674d95a95de9c5ee76b (patch)
treede5a3d0ce3bceca0cc3029b7bcfa8ecba8b80732 /addons
parent2aa977777fca277eba401ac0c1ebbd6e9049d6f9 (diff)
downloadpardes-60c428d74f8aad24d002a674d95a95de9c5ee76b.tar.gz
pardes-60c428d74f8aad24d002a674d95a95de9c5ee76b.zip
image: a top-down BMP opens: stb's info gives its height negative (its loader takes the length), and addons/image/image.zig cast it to u32 (`integer does not fit`, in the session at the pane's open, on main: the test of the change before); now `size` (no size: nothing to show; a negative height its length), and a job copies the pixels by the load's own size, refusing a load whose size is not info's (it copied by info's); a user could hit it by opening a valid BMP
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'addons')
-rw-r--r--addons/image/image.zig14
1 files changed, 12 insertions, 2 deletions
diff --git a/addons/image/image.zig b/addons/image/image.zig
index 48135458..8e2cb32a 100644
--- a/addons/image/image.zig
+++ b/addons/image/image.zig
@@ -33,7 +33,14 @@ fn info(bytes: []const u8) ?[2]u32 {
defer job = null;
var w: c_int, var h: c_int = .{ 0, 0 };
if (bytes.len == 0 or bytes.len > std.math.maxInt(c_int) or pa_image_info(bytes.ptr, @intCast(bytes.len), &w, &h) == 0) return null;
- return .{ @intCast(w), @intCast(h) };
+ return size(w, h);
+}
+
+/// stb's width and height as a size: a top-down BMP's height is negative in
+/// its info (stb's loader takes the length of it); none, nothing to show.
+fn size(w: c_int, h: c_int) ?[2]u32 {
+ if (w <= 0 or h == 0) return null;
+ return .{ @intCast(w), @abs(h) };
}
/// Each pane's pixels in this process, by its block's address: a draw's
@@ -83,9 +90,12 @@ pub const Image = extern struct {
defer job = null;
var w: c_int, var h: c_int = .{ 0, 0 };
if (in.len == 0 or in.len > std.math.maxInt(c_int) or pa_image_info(in.ptr, @intCast(in.len), &w, &h) == 0) return null;
- const wh: [2]u32 = .{ @intCast(w), @intCast(h) };
+ const wh = size(w, h) orelse return null;
if (@as(u64, wh[0]) * wh[1] > max_pixels) return null;
var px = pa_image_load(in.ptr, @intCast(in.len), &w, &h) orelse return null;
+ // The pixels are the load's: copied by its size, never info's alone.
+ const loaded = size(w, h) orelse return null;
+ if (loaded[0] != wh[0] or loaded[1] != wh[1]) return null;
const longest: u64 = @max(wh[0], wh[1]);
var nw, var nh = wh;
if (longest > max_dim) {