You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2015/07/09 07:04:20 UTC

trafficserver git commit: TS-3747: Error in Huffman decoder for HPACK

Repository: trafficserver
Updated Branches:
  refs/heads/master 2de96e8cd -> b04bc9b6a


TS-3747: Error in Huffman decoder for HPACK


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/b04bc9b6
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/b04bc9b6
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/b04bc9b6

Branch: refs/heads/master
Commit: b04bc9b6adde276b07aa74549daac4ca4b5341e0
Parents: 2de96e8
Author: Bryan Call <bc...@apache.org>
Authored: Wed Jul 8 22:02:44 2015 -0700
Committer: Bryan Call <bc...@apache.org>
Committed: Wed Jul 8 22:02:44 2015 -0700

----------------------------------------------------------------------
 proxy/http2/HuffmanCodec.cc     |  5 ++++-
 proxy/http2/Makefile.am         | 13 ++++++++++++
 proxy/http2/test_Huffmancode.cc | 38 ++++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b04bc9b6/proxy/http2/HuffmanCodec.cc
----------------------------------------------------------------------
diff --git a/proxy/http2/HuffmanCodec.cc b/proxy/http2/HuffmanCodec.cc
index adf5ecf..0efe589 100644
--- a/proxy/http2/HuffmanCodec.cc
+++ b/proxy/http2/HuffmanCodec.cc
@@ -290,6 +290,7 @@ static const huffman_entry huffman_table[] = {{0x1ff8, 13},
 typedef struct node {
   node *left, *right;
   char ascii_code;
+  bool leaf_node;
 } Node;
 
 Node *HUFFMAN_TREE_ROOT;
@@ -301,6 +302,7 @@ make_huffman_tree_node()
   n->left = NULL;
   n->right = NULL;
   n->ascii_code = '\0';
+  n->leaf_node = false;
   return n;
 }
 
@@ -327,6 +329,7 @@ make_huffman_tree()
       bit_len--;
     }
     current->ascii_code = i;
+    current->leaf_node = true;
   }
   return root;
 }
@@ -370,7 +373,7 @@ huffman_decode(char *dst_start, const uint8_t *src, uint32_t src_len)
       current = current->left;
     }
 
-    if (current->ascii_code) {
+    if (current->leaf_node == true) {
       *dst_end = current->ascii_code;
       ++dst_end;
       current = HUFFMAN_TREE_ROOT;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b04bc9b6/proxy/http2/Makefile.am
----------------------------------------------------------------------
diff --git a/proxy/http2/Makefile.am b/proxy/http2/Makefile.am
index 177d9e6..7dc06f8 100644
--- a/proxy/http2/Makefile.am
+++ b/proxy/http2/Makefile.am
@@ -46,3 +46,16 @@ libhttp2_a_SOURCES = \
   Http2SessionAccept.h \
   HuffmanCodec.cc \
   HuffmanCodec.h
+
+noinst_PROGRAMS = \
+  test_Huffmancode
+
+TESTS = test_Huffmancode
+
+test_Huffmancode_LDADD = \
+  $(top_builddir)/lib/ts/libtsutil.la
+
+test_Huffmancode_SOURCES = \
+  test_Huffmancode.cc \
+  HuffmanCodec.cc \
+  HuffmanCodec.h

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/b04bc9b6/proxy/http2/test_Huffmancode.cc
----------------------------------------------------------------------
diff --git a/proxy/http2/test_Huffmancode.cc b/proxy/http2/test_Huffmancode.cc
new file mode 100644
index 0000000..7d513d9
--- /dev/null
+++ b/proxy/http2/test_Huffmancode.cc
@@ -0,0 +1,38 @@
+#include "HuffmanCodec.h"
+#include <stdlib.h>
+#include <iostream>
+
+using namespace std;
+
+void
+test()
+{
+  char *dst_start = (char *)malloc(1024 * 2);
+  char string[1024];
+  for (int i = 0; i < 1024; i++) {
+    int num = rand();
+    string[i] = (char)num;
+  }
+  const uint8_t *src = (const uint8_t *)string;
+  uint32_t src_len = sizeof(string);
+
+  int bytes = huffman_decode(dst_start, src, src_len);
+
+  cout << "bytes: " << bytes << endl;
+  for (int i = 0; i < bytes; i++) {
+    cout << i << " " << (int)dst_start[i] << " " << dst_start[i] << endl;
+  }
+}
+
+int
+main()
+{
+  hpack_huffman_init();
+
+  for (int i = 0; i < 100; i++) {
+    test();
+  }
+
+  hpack_huffman_fin();
+  return 0;
+}