terminal/kitty-gfx: ignore extra base64 padding

This commit is contained in:
Mitchell Hashimoto
2023-08-23 21:52:50 -07:00
parent 21ce787cff
commit bf7054eeb6
2 changed files with 15 additions and 4 deletions

View File

@ -41,7 +41,11 @@ pub fn execute(
return null; return null;
} }
log.debug("executing kitty graphics command: {}", .{cmd.control}); log.debug("executing kitty graphics command: {}", .{cmd: {
var copy = cmd.*;
copy.data = "";
break :cmd copy;
}});
const resp_: ?Response = switch (cmd.control) { const resp_: ?Response = switch (cmd.control) {
.query => query(alloc, cmd), .query => query(alloc, cmd),

View File

@ -241,9 +241,16 @@ pub const LoadingImage = struct {
const start_i = self.data.items.len; const start_i = self.data.items.len;
self.data.items.len = start_i + size; self.data.items.len = start_i + size;
const buf = self.data.items[start_i..]; const buf = self.data.items[start_i..];
Base64Decoder.decode(buf, data) catch |err| { Base64Decoder.decode(buf, data) catch |err| switch (err) {
log.warn("failed to decode base64 data: {}", .{err}); // We have to ignore invalid padding because lots of encoders
return error.InvalidData; // add the wrong padding. Since we validate image data later
// (PNG decode or simple dimensions check), we can ignore this.
error.InvalidPadding => {},
else => {
log.warn("failed to decode base64 data: {}", .{err});
return error.InvalidData;
},
}; };
} }