Do not allocate when a Kitty payload chunk decodes to no bytes.

This commit is contained in:
Michael Grant
2026-10-09 22:50:02 +02:00
parent 4b13e0c3d7
commit e29f9f7076
2 changed files with 12 additions and 0 deletions

View File

@@ -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);

View File

@@ -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'))