summaryrefslogtreecommitdiff
path: root/src/image.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-23 17:10:58 -0300
committerGabriel Schneider <[email protected]>2026-10-23 17:10:58 -0300
commit0073d05329335dbb0eb85f5c3044e42805d144e5 (patch)
tree744edfc317719b2018b1c3a8657c223aec058d47 /src/image.zig
parenta8b457a306a4442975210bcac3f04b56513c61c3 (diff)
downloadpardes-0073d05329335dbb0eb85f5c3044e42805d144e5.tar.gz
pardes-0073d05329335dbb0eb85f5c3044e42805d144e5.zip
Callstack lists every caller and pages a tree too big for one query; memory bounds and resident-size fixes
Callstack walks while the server answers, counts on the message row past a second, puts test callers last at each level, and ends a tree past one query's memory (memory.limits.arena.lsp_query, a 256 MiB region taken and given back per query) in a row whose Callstack shows the next page. Grep reads whole files. New hard limits: undo text per file, image decode pixels, the LSP snapshot of other open files, one paste. Safe builds no longer fill worst-case buffers with 0xAA (memory.unfilled), big regions are kept off transparent huge pages, and malloc_trim runs after big results. Also: Look's git show pages into a +Diff, and dropped marks in File. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/image.zig')
-rw-r--r--src/image.zig8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/image.zig b/src/image.zig
index 8bf9de08..5797ce9e 100644
--- a/src/image.zig
+++ b/src/image.zig
@@ -768,7 +768,13 @@ pub fn readable(bytes: []const u8) bool {
/// decode + downscale to RGBA, gpa-owned. Returns null on any failure — the
/// pane then simply shows a blank body.
pub fn decode(gpa: std.mem.Allocator, bytes: []const u8) ?struct { rgba: []u8, w: usize, h: usize } {
- if (bytes.len == 0) return null;
+ if (bytes.len == 0 or bytes.len > std.math.maxInt(c_int)) return null;
+ // Bounded before decoding: a few KB of PNG can name gigapixels.
+ var iw: c_int = 0;
+ var ih: c_int = 0;
+ var ic: c_int = 0;
+ if (stbi_info_from_memory(bytes.ptr, @intCast(bytes.len), &iw, &ih, &ic) != 1) return null;
+ if (@as(usize, @intCast(@max(0, iw))) * @as(usize, @intCast(@max(0, ih))) > @import("memory.zig").limits.image_decode_pixels) return null;
var img = zstbi.Image.loadFromMemory(bytes, 4) catch return null; // 4 = RGBA
defer img.deinit();
var scaled: ?zstbi.Image = null;