[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Descriptor decompression inappropriately stripped trailing newline



commit 32a3d26267b24bc441f81ad3559d2acc318eb125
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Wed Nov 21 15:28:36 2018 -0800

    Descriptor decompression inappropriately stripped trailing newline
    
    Oops, our decompression helper stripped trailing whitespaces. This wasn't
    noticeable to our parser, but it does throw off digesting...
    
      import stem.descriptor.remote
    
      digest = 'BsaDvyZyHjBDGWCYpMx0Du3N1Mn2uMfNF7PjgizQC1s'
    
      desc = stem.descriptor.remote.get_microdescriptors([digest]).run()[0]
      print('digest: %s (expected %s)' % (desc.digest(), digest))
    
      ============================================================
    
      % python scrap.py
      digest: j8kC3P07m9dL45ll1O0PSpvfOfxLtzAWqJYjzvwLEcM (expected BsaDvyZyHjBDGWCYpMx0Du3N1Mn2uMfNF7PjgizQC1s)
---
 stem/descriptor/remote.py      | 8 ++++----
 test/unit/descriptor/remote.py | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py
index 78dd8367..b27bb39d 100644
--- a/stem/descriptor/remote.py
+++ b/stem/descriptor/remote.py
@@ -948,9 +948,9 @@ def _decompress(data, encoding):
   """
 
   if encoding == Compression.PLAINTEXT:
-    return data.strip()
+    return data
   elif encoding in (Compression.GZIP, 'deflate'):
-    return zlib.decompress(data, zlib.MAX_WBITS | 32).strip()
+    return zlib.decompress(data, zlib.MAX_WBITS | 32)
   elif encoding == Compression.ZSTD:
     if not stem.prereq.is_zstd_available():
       raise ImportError('Decompressing zstd data requires https://pypi.python.org/pypi/zstandard')
@@ -961,13 +961,13 @@ def _decompress(data, encoding):
     with zstd.ZstdDecompressor().write_to(output_buffer) as decompressor:
       decompressor.write(data)
 
-    return output_buffer.getvalue().strip()
+    return output_buffer.getvalue()
   elif encoding == Compression.LZMA:
     if not stem.prereq.is_lzma_available():
       raise ImportError('Decompressing lzma data requires https://docs.python.org/3/library/lzma.html')
 
     import lzma
-    return lzma.decompress(data).strip()
+    return lzma.decompress(data)
   else:
     raise ValueError("'%s' isn't a recognized type of encoding" % encoding)
 
diff --git a/test/unit/descriptor/remote.py b/test/unit/descriptor/remote.py
index e6171852..aab5f5d6 100644
--- a/test/unit/descriptor/remote.py
+++ b/test/unit/descriptor/remote.py
@@ -320,7 +320,7 @@ class TestDescriptorDownloader(unittest.TestCase):
     self.assertEqual('moria1', desc.nickname)
     self.assertEqual('128.31.0.34', desc.address)
     self.assertEqual('9695DFC35FFEB861329B9F1AB04C46397020CE31', desc.fingerprint)
-    self.assertEqual(TEST_DESCRIPTOR.strip(), desc.get_bytes())
+    self.assertEqual(TEST_DESCRIPTOR, desc.get_bytes())
 
   @patch(URL_OPEN, _dirport_mock(b'some malformed stuff'))
   def test_query_with_malformed_content(self):

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits