From 0663f1f8dbb0658b3892b7071eec746e37c594b8 Mon Sep 17 00:00:00 2001 From: m-holger Date: Wed, 7 Aug 2024 16:19:16 +0100 Subject: [PATCH] Guard against 0 byte writes in Pl_Buffer and Pl_String --- libqpdf/Pl_Buffer.cc | 3 +++ libqpdf/Pl_String.cc | 3 +++ 2 files changed, 6 insertions(+) diff --git a/libqpdf/Pl_Buffer.cc b/libqpdf/Pl_Buffer.cc index 9994bedd..1babe6e1 100644 --- a/libqpdf/Pl_Buffer.cc +++ b/libqpdf/Pl_Buffer.cc @@ -19,6 +19,9 @@ Pl_Buffer::~Pl_Buffer() // NOLINT (modernize-use-equals-default) void Pl_Buffer::write(unsigned char const* buf, size_t len) { + if (!len) { + return; + } m->data.append(reinterpret_cast(buf), len); m->ready = false; diff --git a/libqpdf/Pl_String.cc b/libqpdf/Pl_String.cc index 9009268a..1369c17d 100644 --- a/libqpdf/Pl_String.cc +++ b/libqpdf/Pl_String.cc @@ -21,6 +21,9 @@ Pl_String::~Pl_String() // NOLINT (modernize-use-equals-default) void Pl_String::write(unsigned char const* buf, size_t len) { + if (!len) { + return; + } m->s.append(reinterpret_cast(buf), len); if (getNext(true)) { getNext()->write(buf, len);