This is an automated email from the ASF dual-hosted git repository.

maskit pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/quic-latest by this push:
     new a114d46  Fix another bug around PN calculation
a114d46 is described below

commit a114d463a69f664868bc0171e26994ddf9f394d9
Author: Masakazu Kitajo <[email protected]>
AuthorDate: Tue Jun 26 10:39:43 2018 +0900

    Fix another bug around PN calculation
---
 iocore/net/quic/QUICPacket.cc | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/iocore/net/quic/QUICPacket.cc b/iocore/net/quic/QUICPacket.cc
index 2aa5dee..19a86d5 100644
--- a/iocore/net/quic/QUICPacket.cc
+++ b/iocore/net/quic/QUICPacket.cc
@@ -750,13 +750,27 @@ QUICPacket::decode_packet_number(QUICPacketNumber &dst, 
QUICPacketNumber src, si
 {
   ink_assert(len == 1 || len == 2 || len == 4);
 
-  uint64_t maximum_diff       = 1ULL << (len * 8);
+  uint64_t maximum_diff = 0;
+  switch (len) {
+  case 1:
+    maximum_diff = 0x80;
+    break;
+  case 2:
+    maximum_diff = 0x4000;
+    break;
+  case 4:
+    maximum_diff = 0x40000000;
+    break;
+  default:
+    ink_assert(!"len must be 1, 2 or 4");
+  }
   QUICPacketNumber base       = largest_acked & (~(maximum_diff - 1));
   QUICPacketNumber candidate1 = base + src;
   QUICPacketNumber candidate2 = base + src + maximum_diff;
+  QUICPacketNumber expected   = largest_acked + 1;
 
-  if (((candidate1 > largest_acked) ? (candidate1 - largest_acked) : 
(largest_acked - candidate1)) <
-      ((candidate2 > largest_acked) ? (candidate2 - largest_acked) : 
(largest_acked - candidate2))) {
+  if (((candidate1 > expected) ? (candidate1 - expected) : (expected - 
candidate1)) <
+      ((candidate2 > expected) ? (candidate2 - expected) : (expected - 
candidate2))) {
     dst = candidate1;
   } else {
     dst = candidate2;

Reply via email to