From 0c24c835359cb6d690f6e38f90d5177b72f73f97 Mon Sep 17 00:00:00 2001 From: Abdelhakim Qbaich Date: Sat, 4 Apr 2026 16:48:30 -0400 Subject: [PATCH] Use max_blen instead of constant --- src/plugins/streamers/oasis/db_plugin/dbOASISReader.cc | 3 ++- src/tl/tl/tlDeflate.cc | 3 +-- src/tl/tl/tlDeflate.h | 10 +++++++++- src/tl/tl/tlStream.cc | 6 ++++++ src/tl/tl/tlStream.h | 10 ++++++++++ 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/plugins/streamers/oasis/db_plugin/dbOASISReader.cc b/src/plugins/streamers/oasis/db_plugin/dbOASISReader.cc index 260020767..97d98db69 100644 --- a/src/plugins/streamers/oasis/db_plugin/dbOASISReader.cc +++ b/src/plugins/streamers/oasis/db_plugin/dbOASISReader.cc @@ -206,7 +206,7 @@ OASISReader::get_str (std::string &s) size_t l = 0; get_size (l); - const size_t chunk_size = 32767; + const size_t chunk_size = m_stream.max_blen (); if (l <= chunk_size) { char *b = (char *) m_stream.get (l); @@ -3677,3 +3677,4 @@ OASISReader::do_read_cell (db::cell_index_type cell_index, db::Layout &layout) } } + diff --git a/src/tl/tl/tlDeflate.cc b/src/tl/tl/tlDeflate.cc index e2a2b2cde..d8aab26bd 100644 --- a/src/tl/tl/tlDeflate.cc +++ b/src/tl/tl/tlDeflate.cc @@ -246,7 +246,7 @@ InflateFilter::~InflateFilter () const char * InflateFilter::get (size_t n) { - tl_assert (n < sizeof (m_buffer) / 2); + tl_assert (n <= max_blen ()); while ((m_b_insert + sizeof (m_buffer) - m_b_read) % sizeof (m_buffer) < n) { if (! process ()) { @@ -558,4 +558,3 @@ DeflateFilter::flush () } } - diff --git a/src/tl/tl/tlDeflate.h b/src/tl/tl/tlDeflate.h index 712921d62..3fee4ebcd 100644 --- a/src/tl/tl/tlDeflate.h +++ b/src/tl/tl/tlDeflate.h @@ -211,10 +211,18 @@ public: * @brief Get the next byte(s) * * This method returns a contiguous block of decoded bytes with the given length. - * The maximum size of the block available is half the buffer size. + * The maximum size of the block available is given by max_blen(). */ const char *get (size_t n); + /** + * @brief Obtain the maximum number of bytes available for a single get() call + */ + size_t max_blen () const + { + return sizeof (m_buffer) / 2 - 1; + } + /** * @brief Undo the last "get" operation * diff --git a/src/tl/tl/tlStream.cc b/src/tl/tl/tlStream.cc index 442218e28..33a8f72b0 100644 --- a/src/tl/tl/tlStream.cc +++ b/src/tl/tl/tlStream.cc @@ -604,6 +604,12 @@ InputStream::get (size_t n, bool bypass_inflate) } } +size_t +InputStream::max_blen () const +{ + return mp_inflate ? mp_inflate->max_blen () : std::numeric_limits::max (); +} + void InputStream::unget (size_t n) { diff --git a/src/tl/tl/tlStream.h b/src/tl/tl/tlStream.h index 9e2f03b61..99551c86d 100644 --- a/src/tl/tl/tlStream.h +++ b/src/tl/tl/tlStream.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace tl @@ -498,6 +499,15 @@ public: return m_blen; } + /** + * @brief Obtain the maximum number of bytes available for a single get() call + * + * This is an API limit, not the actual number of bytes available right now. + * For inflating streams this reports the maximum contiguous chunk size the + * inflating filter can provide in one get() call. + */ + size_t max_blen () const; + /** * @brief Get the source specification (the file name) *