public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/zstr] f44: Add patch to better detect uncompressed files
@ 2026-11-30 21:22 Jerry James
  0 siblings, 0 replies; only message in thread
From: Jerry James @ 2026-11-30 21:22 UTC (permalink / raw)
  To: git-commits

A new commit has been pushed.

Repo   : rpms/zstr
Branch : f44
Commit : 89f6060de29454f6742acde4dd012f0ed9a83037
Author : Jerry James <loganjerry@gmail.com>
Date   : 2026-11-30T14:22:21-07:00
Stats  : +93/-7 in 3 file(s)
URL    : https://src.fedoraproject.org/rpms/zstr/c/89f6060de29454f6742acde4dd012f0ed9a83037?branch=f44

Log:
Add patch to better detect uncompressed files

---
diff --git a/79.patch b/79.patch
new file mode 100644
index 0000000..f047ecd
--- /dev/null
+++ b/79.patch
@@ -0,0 +1,66 @@
+From 8ad7175507217dffe33a5c21c000a2a1d5f11759 Mon Sep 17 00:00:00 2001
+From: Jerry James <loganjerry@gmail.com>
+Date: Mon, 16 Nov 2026 16:21:13 -0700
+Subject: [PATCH] Do a test decompression if non-text is detected
+
+"Unluckily" crafted text files might have a header compliant with the
+zlib magic structure. If non-text is detected, try decompressing the
+first block. If that fails, fall back to reading as text.
+---
+ src/zstr.hpp | 43 ++++++++++++++++++++++++++++++++++++++++++-
+ 1 file changed, 42 insertions(+), 1 deletion(-)
+
+diff --git a/src/zstr.hpp b/src/zstr.hpp
+index 97859b0..9c2bb77 100644
+--- a/src/zstr.hpp
++++ b/src/zstr.hpp
+@@ -330,7 +330,48 @@ class istreambuf
+                 if (auto_detect && ! auto_detect_run)
+                 {
+                     auto_detect_run = true;
+-                    is_text = !is_compressed(in_buff_start, in_buff_end);
++                    if (!is_compressed(in_buff_start, in_buff_end))
++                    {
++                        is_text = true;
++                    }
++                    else
++                    {
++                        // Try inflate() on the initial buffer to catch spurious zlib header matches
++                        zstrm_p = std::unique_ptr<detail::z_stream_wrapper>(new detail::z_stream_wrapper(true, Z_DEFAULT_COMPRESSION, window_bits));
++                        zstrm_p->next_in = reinterpret_cast< decltype(zstrm_p->next_in) >(in_buff_start);
++                        zstrm_p->avail_in = uint32_t(in_buff_end - in_buff_start);
++                        zstrm_p->next_out = reinterpret_cast< decltype(zstrm_p->next_out) >(out_buff_free_start);
++                        zstrm_p->avail_out = uint32_t((out_buff.get() + buff_size) - out_buff_free_start);
++                        int ret = inflate(zstrm_p.get(), Z_NO_FLUSH);
++                        if (ret == Z_OK || ret == Z_STREAM_END)
++                        {
++                            in_buff_start = reinterpret_cast< decltype(in_buff_start) >(
++#ifdef MINIZ
++                                const_cast< unsigned char* >(zstrm_p->next_in);
++#else
++                                zstrm_p->next_in
++#endif
++                            );
++                            in_buff_end = in_buff_start + zstrm_p->avail_in;
++                            out_buff_free_start = reinterpret_cast< decltype(out_buff_free_start) >(zstrm_p->next_out);
++                            assert(out_buff_free_start + zstrm_p->avail_out == out_buff.get() + buff_size);
++
++                            if (ret == Z_STREAM_END) {
++                                // if stream ended, deallocate inflator
++                                zstrm_p.reset();
++                            }
++                            continue;
++                        }
++                        else if (ret == Z_DATA_ERROR || ret == Z_NEED_DICT)
++                        {
++                            zstrm_p.reset();
++                            is_text = true;
++                        }
++                        else
++                        {
++                            throw Exception(zstrm_p.get(), ret);
++                        }
++                    }
+                 }
+                 if (is_text)
+                 {

diff --git a/zstr-zlib-ng.patch b/zstr-zlib-ng.patch
index 4157bc7..ca08de6 100644
--- a/zstr-zlib-ng.patch
+++ b/zstr-zlib-ng.patch
@@ -53,8 +53,8 @@
  )
  install(EXPORT zstrTargets
    FILE zstrTargets.cmake
---- zstr-1.2.0/src/zstr.hpp.orig	2026-09-24 16:10:35.000000000 -0600
-+++ zstr-1.2.0/src/zstr.hpp	2026-09-25 08:36:20.911888666 -0600
+--- zstr-1.2.0/src/zstr.hpp.orig	2026-11-29 07:11:16.259924537 -0700
++++ zstr-1.2.0/src/zstr.hpp	2026-11-29 07:12:21.687043187 -0700
 @@ -15,7 +15,7 @@
  #ifdef MINIZ
  #include <miniz.h>
@@ -128,7 +128,25 @@
                      if (in_buff_end == in_buff_start) break; // end of input
                  }
                  // auto detect if the stream contains text or deflate data
-@@ -349,7 +349,7 @@ public:
+@@ -342,7 +342,7 @@ public:
+                         zstrm_p->avail_in = uint32_t(in_buff_end - in_buff_start);
+                         zstrm_p->next_out = reinterpret_cast< decltype(zstrm_p->next_out) >(out_buff_free_start);
+                         zstrm_p->avail_out = uint32_t((out_buff.get() + buff_size) - out_buff_free_start);
+-                        int ret = inflate(zstrm_p.get(), Z_NO_FLUSH);
++                        int ret = zng_inflate(zstrm_p.get(), Z_NO_FLUSH);
+                         if (ret == Z_OK || ret == Z_STREAM_END)
+                         {
+                             in_buff_start = reinterpret_cast< decltype(in_buff_start) >(
+@@ -352,7 +352,7 @@ public:
+                                 zstrm_p->next_in
+ #endif
+                             );
+-                            in_buff_end = in_buff_start + zstrm_p->avail_in;
++                            in_buff_end = const_cast<char *>(in_buff_start) + zstrm_p->avail_in;
+                             out_buff_free_start = reinterpret_cast< decltype(out_buff_free_start) >(zstrm_p->next_out);
+                             assert(out_buff_free_start + zstrm_p->avail_out == out_buff.get() + buff_size);
+ 
+@@ -390,7 +390,7 @@ public:
                      zstrm_p->avail_in = uint32_t(in_buff_end - in_buff_start);
                      zstrm_p->next_out = reinterpret_cast< decltype(zstrm_p->next_out) >(out_buff_free_start);
                      zstrm_p->avail_out = uint32_t((out_buff.get() + buff_size) - out_buff_free_start);
@@ -137,7 +155,7 @@
                      // process return code
                      if (ret != Z_OK && ret != Z_STREAM_END) throw Exception(zstrm_p.get(), ret);
                      // update in&out pointers following inflate()
-@@ -360,7 +360,7 @@ public:
+@@ -401,7 +401,7 @@ public:
                          zstrm_p->next_in
  #endif
                      );
@@ -146,7 +164,7 @@
                      out_buff_free_start = reinterpret_cast< decltype(out_buff_free_start) >(zstrm_p->next_out);
                      assert(out_buff_free_start + zstrm_p->avail_out == out_buff.get() + buff_size);
  
-@@ -382,7 +382,7 @@ public:
+@@ -423,7 +423,7 @@ public:
  private:
      std::streambuf * sbuf_p;
      std::unique_ptr<char[]> in_buff;
@@ -155,7 +173,7 @@
      char * in_buff_end;
      std::unique_ptr<char[]> out_buff;
      std::unique_ptr<detail::z_stream_wrapper> zstrm_p;
-@@ -424,7 +424,7 @@ public:
+@@ -465,7 +465,7 @@ public:
          {
              zstrm_p->next_out = reinterpret_cast< decltype(zstrm_p->next_out) >(out_buff.get());
              zstrm_p->avail_out = uint32_t(buff_size);
@@ -164,7 +182,7 @@
              if (ret != Z_OK && ret != Z_STREAM_END && ret != Z_BUF_ERROR) {
                  failed = true;
                  throw Exception(zstrm_p.get(), ret);
-@@ -492,7 +492,7 @@ public:
+@@ -533,7 +533,7 @@ public:
          zstrm_p->next_in = nullptr;
          zstrm_p->avail_in = 0;
          if (deflate_loop(Z_FINISH) != 0) return -1;

diff --git a/zstr.spec b/zstr.spec
index 9716c71..05f9ab6 100644
--- a/zstr.spec
+++ b/zstr.spec
@@ -13,6 +13,8 @@ License:        MIT
 URL:            https://github.com/mateidavid/zstr
 VCS :           git:%{url}.git
 Source:         %{url}/archive/v%{version}/%{name}-%{version}.tar.gz
+# Do a test decompression if non-text is detected
+Patch:          %{url}/pull/79.patch
 # Use zlib-ng directly rather than via the compatibility interface
 Patch:          %{name}-zlib-ng.patch
 

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-30 21:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 21:22 [rpms/zstr] f44: Add patch to better detect uncompressed files Jerry James

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox