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

[tor-commits] [metrics-lib/release] Fix encoding bug in RelayDirectoryImpl and NetworkStatusImpl.



commit fadcaa4b200e9a8af9c1f47c1458880d0245a9b6
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Mon May 29 14:35:40 2017 +0200

    Fix encoding bug in RelayDirectoryImpl and NetworkStatusImpl.
---
 CHANGELOG.md                                                         | 4 ++++
 src/main/java/org/torproject/descriptor/impl/NetworkStatusImpl.java  | 4 +++-
 src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java | 4 +++-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0cedcd1..143494e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,10 @@
    - Move descriptor digest computation to DescriptorImpl.
    - Fix a bug in digest computation by making sure that the
      descriptor string actually contains the end token.
+   - Fix a bug where both RelayDirectoryImpl and all NetworkStatusImpl
+     subclasses fail to get indexes right if parts of raw descriptor
+     strings contain non-ASCII chars.  In practice, this only affects
+     version 1 directories which were last archived in 2007.
 
 
 # Changes in version 1.7.0 - 2017-05-17
diff --git a/src/main/java/org/torproject/descriptor/impl/NetworkStatusImpl.java b/src/main/java/org/torproject/descriptor/impl/NetworkStatusImpl.java
index f67c32a..93acf7b 100644
--- a/src/main/java/org/torproject/descriptor/impl/NetworkStatusImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/NetworkStatusImpl.java
@@ -8,6 +8,7 @@ import org.torproject.descriptor.DirSourceEntry;
 import org.torproject.descriptor.DirectorySignature;
 import org.torproject.descriptor.NetworkStatusEntry;
 
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.SortedMap;
@@ -33,7 +34,8 @@ public abstract class NetworkStatusImpl extends DescriptorImpl {
     if (this.rawDescriptorBytes.length == 0) {
       throw new DescriptorParseException("Descriptor is empty.");
     }
-    String descriptorString = new String(rawDescriptorBytes);
+    String descriptorString = new String(rawDescriptorBytes,
+        StandardCharsets.US_ASCII);
     int firstRIndex = this.findFirstIndexOfKeyword(descriptorString,
         Key.R.keyword);
     int endIndex = descriptorString.length();
diff --git a/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java
index 3c810e0..27887e6 100644
--- a/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java
@@ -8,6 +8,7 @@ import org.torproject.descriptor.RelayDirectory;
 import org.torproject.descriptor.RouterStatusEntry;
 import org.torproject.descriptor.ServerDescriptor;
 
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
@@ -56,7 +57,8 @@ public class RelayDirectoryImpl extends DescriptorImpl
     if (this.rawDescriptorBytes.length == 0) {
       throw new DescriptorParseException("Descriptor is empty.");
     }
-    String descriptorString = new String(rawDescriptorBytes);
+    String descriptorString = new String(rawDescriptorBytes,
+        StandardCharsets.US_ASCII);
     int startIndex = 0;
     int firstRouterIndex = this.findFirstIndexOfKeyword(descriptorString,
         Key.ROUTER.keyword);



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