qt5/src/poppler-qiodeviceoutstream.cc | 20 +++++++++++++++----- qt6/src/poppler-qiodeviceoutstream.cc | 20 +++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-)
New commits: commit 8846eb5d2e1466cf0aaa1f38d5452b60c47bd9dc Author: Albert Astals Cid <aa...@kde.org> Date: Wed Dec 30 17:37:41 2020 +0100 QIODeviceOutStream: allocate memory dynamically Instead of using a fixed size array. I've only seen this being problematic in oss-fuzz created files, but I don't see why an actual file wouldn't create issues here too, so even if this is a bit slower, be on the safe side. diff --git a/qt5/src/poppler-qiodeviceoutstream.cc b/qt5/src/poppler-qiodeviceoutstream.cc index 002bdb00..d6ee0cdb 100644 --- a/qt5/src/poppler-qiodeviceoutstream.cc +++ b/qt5/src/poppler-qiodeviceoutstream.cc @@ -1,6 +1,7 @@ /* poppler-qiodevicestream.cc: Qt5 interface to poppler * Copyright (C) 2008, Pino Toscano <p...@kde.org> * Copyright (C) 2013 Adrian Johnson <ajohn...@redneon.com> + * Copyright (C) 2020 Albert Astals Cid <aa...@kde.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,8 +24,6 @@ #include <cstdio> -#define QIODeviceOutStreamBufSize 8192 - namespace Poppler { QIODeviceOutStream::QIODeviceOutStream(QIODevice *device) : m_device(device) { } @@ -43,15 +42,26 @@ void QIODeviceOutStream::put(char c) m_device->putChar(c); } +static int poppler_qvasprintf(char **buf_ptr, const char *format, va_list ap) +{ + va_list ap_copy; + va_copy(ap_copy, ap); + const size_t size = qvsnprintf(nullptr, 0, format, ap_copy) + 1; + va_end(ap_copy); + *buf_ptr = new char[size]; + + return qvsnprintf(*buf_ptr, size, format, ap); +} + void QIODeviceOutStream::printf(const char *format, ...) { va_list ap; va_start(ap, format); - char buf[QIODeviceOutStreamBufSize]; - size_t bufsize = 0; - bufsize = qvsnprintf(buf, QIODeviceOutStreamBufSize - 1, format, ap); + char *buf; + const size_t bufsize = poppler_qvasprintf(&buf, format, ap); va_end(ap); m_device->write(buf, bufsize); + delete[] buf; } } diff --git a/qt6/src/poppler-qiodeviceoutstream.cc b/qt6/src/poppler-qiodeviceoutstream.cc index e300fe0d..c9c61e33 100644 --- a/qt6/src/poppler-qiodeviceoutstream.cc +++ b/qt6/src/poppler-qiodeviceoutstream.cc @@ -1,6 +1,7 @@ /* poppler-qiodevicestream.cc: Qt6 interface to poppler * Copyright (C) 2008, Pino Toscano <p...@kde.org> * Copyright (C) 2013 Adrian Johnson <ajohn...@redneon.com> + * Copyright (C) 2020 Albert Astals Cid <aa...@kde.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,8 +24,6 @@ #include <cstdio> -#define QIODeviceOutStreamBufSize 8192 - namespace Poppler { QIODeviceOutStream::QIODeviceOutStream(QIODevice *device) : m_device(device) { } @@ -43,15 +42,26 @@ void QIODeviceOutStream::put(char c) m_device->putChar(c); } +static int poppler_qvasprintf(char **buf_ptr, const char *format, va_list ap) +{ + va_list ap_copy; + va_copy(ap_copy, ap); + const size_t size = qvsnprintf(nullptr, 0, format, ap_copy) + 1; + va_end(ap_copy); + *buf_ptr = new char[size]; + + return qvsnprintf(*buf_ptr, size, format, ap); +} + void QIODeviceOutStream::printf(const char *format, ...) { va_list ap; va_start(ap, format); - char buf[QIODeviceOutStreamBufSize]; - size_t bufsize = 0; - bufsize = qvsnprintf(buf, QIODeviceOutStreamBufSize - 1, format, ap); + char *buf; + const size_t bufsize = poppler_qvasprintf(&buf, format, ap); va_end(ap); m_device->write(buf, bufsize); + delete[] buf; } } _______________________________________________ poppler mailing list poppler@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/poppler