From 13565f5421ea85def10811ef0445b628d5693551 Mon Sep 17 00:00:00 2001 From: ManasBagul23 Date: Thu, 5 Nov 2026 11:34:31 +0530 Subject: [PATCH] imagetops-pstops: fix off-by-one in doc_printf truncation check vsnprintf() returns the number of characters that would have been written for a big-enough buffer, not counting the terminator. When a single doc_printf() call formats exactly sizeof(buffer) characters, "bytes > sizeof(buffer)" is false, so the truncation branch is skipped and doc_write() is told to emit all 1024 bytes of "buffer" - including the NUL terminator vsnprintf left at buffer[1023] in place of the real (dropped) last character. That NUL ends up embedded in the generated PostScript stream. Use >= for the check and drop only the terminator byte, not one more character of real content, when truncating. --- ppd/imagetops-pstops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ppd/imagetops-pstops.c b/ppd/imagetops-pstops.c index bf12609a..4b79830b 100644 --- a/ppd/imagetops-pstops.c +++ b/ppd/imagetops-pstops.c @@ -3622,11 +3622,11 @@ doc_printf(pstops_doc_t *doc, // I - Document information bytes = vsnprintf(buffer, sizeof(buffer), format, ap); va_end(ap); - if ((size_t)bytes > sizeof(buffer)) + if ((size_t)bytes >= sizeof(buffer)) { if (log) log(ld, CF_LOGLEVEL_ERROR, "ppdFilterPSToPS: Buffer overflow detected, truncating."); - bytes = sizeof(buffer); + bytes = sizeof(buffer) - 1; } doc_write(doc, buffer, (size_t)bytes);