diff --git a/image-kitty.c b/image-kitty.c index 284511549..572ef856b 100644 --- a/image-kitty.c +++ b/image-kitty.c @@ -952,6 +952,12 @@ kitty_append(struct kitty_state *ks, const u_char *buf, size_t len) free(copy); if (decoded == NULL) return (-1); + + /* Empty decoded chunks need no allocation. */ + if (decodedlen == 0) { + free(decoded); + return (0); + } if (decodedlen > IMAGE_SIZE_LIMIT - ks->rawlen) { free(decoded); return (-1); diff --git a/regress/image-kitty-protocol.sh b/regress/image-kitty-protocol.sh index 08537a1ad..7256e7f6e 100644 --- a/regress/image-kitty-protocol.sh +++ b/regress/image-kitty-protocol.sh @@ -142,6 +142,12 @@ with tempfile.TemporaryDirectory(prefix='tmux-kitty-protocol-') as tmp: check('invalid-reply', origin + graphics('a=T,i=7,p=9,f=32,s=1,v=1', '!!!!'), '5,2', graphics('i=7,p=9', 'EINVAL')) check('quiet-error', origin + graphics('a=T,q=2,i=7,f=32,s=1,v=1', '!!!!'), '5,2') + check('empty-decoded-payload', origin + + graphics('a=T,i=7,f=32,s=1,v=1', ' '), '5,2', + graphics('i=7', 'EINVAL')) + check('empty-decoded-chunk', + graphics(placement + ',m=1', ' ') + origin + + graphics('m=0', pixel), '8,4') check('quiet-ok', origin + graphics('a=t,q=1,i=7,f=32,s=1,v=1', pixel), '5,2') check('quiet-one-error', origin + graphics('a=t,q=1,i=7,f=32,s=1,v=1', '!!!!'), '5,2', graphics('i=7', 'EINVAL'))