[tor-commits] [metrics-web/master] Fix flaw in noise-removing code of hidserv module.

karsten at torproject.org karsten at torproject.org
Fri May 25 19:38:38 UTC 2018


commit 52b1051fb14f4091d3e1e02b0497bad5b0d66ca6
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Fri May 18 16:29:42 2018 +0200

    Fix flaw in noise-removing code of hidserv module.
    
    In the technical report that the hidserv module is based on we write:
    
    "When processing hidden-service statistics, we need to handle the fact
    that they have been obfuscated by relays. As first step, we're
    attempting to remove the additive Laplace-distributed noise by
    rounding up or down to the nearest multiple of bin_size. The idea is
    that it's most likely that noise was added to the closest right side
    of a bin than to the right side of another bin. In step two, we're
    subtracting half of bin_size, because the relay added between 0 and
    bin_size − 1 to the originally observed value."
    
    However, our code has a flaw: we use integer truncation rather which
    always rounds toward zero, whereas we really want to use the floor
    function which rounds towards negative infinity.
    
    The fix is to use Math.floorDiv() for the division rather than common
    integer division and truncation.
    
    Fixes #26022.
---
 src/main/java/org/torproject/metrics/stats/hidserv/Parser.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/torproject/metrics/stats/hidserv/Parser.java b/src/main/java/org/torproject/metrics/stats/hidserv/Parser.java
index 2423526..9c95db5 100644
--- a/src/main/java/org/torproject/metrics/stats/hidserv/Parser.java
+++ b/src/main/java/org/torproject/metrics/stats/hidserv/Parser.java
@@ -243,7 +243,7 @@ public class Parser {
    * right side of a bin and subtracting half of the bin size. */
   private long removeNoise(long reportedNumber, long binSize) {
     long roundedToNearestRightSideOfTheBin =
-        ((reportedNumber + binSize / 2) / binSize) * binSize;
+        Math.floorDiv((reportedNumber + binSize / 2), binSize) * binSize;
     long subtractedHalfOfBinSize =
         roundedToNearestRightSideOfTheBin - binSize / 2;
     return subtractedHalfOfBinSize;



More information about the tor-commits mailing list