]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: qpack: simplify length checks in qpack_decode_fs()
authorFrederic Lecaille <flecaille@haproxy.com>
Thu, 5 Mar 2026 14:29:06 +0000 (15:29 +0100)
committerFrederic Lecaille <flecaille@haproxy.com>
Thu, 5 Mar 2026 14:42:02 +0000 (15:42 +0100)
This patch simplifies the decoding loop by merging the variable-length
integer truncation check (len == -1) with the subsequent buffer
availability check (len < length).

This removes redundant code blocks and improves readability without
changing the decoding logic.

Note that the second removal is correct, as the check was duplicate and
unnecessary."

src/qpack-dec.c

index 04f949029d5706a1f77c8f0b6519295a263c26c9..5e7a243a6ccfe493029422ae1f46c67ac95edc30 100644 (file)
@@ -428,13 +428,7 @@ int qpack_decode_fs(const unsigned char *raw, uint64_t len, struct buffer *tmp,
                        qpack_debug_printf(stderr, " n=%d t=%d index=%llu", !!n, !!static_tbl, (unsigned long long)index);
                        h = *raw & 0x80;
                        length = qpack_get_varint(&raw, &len, 7);
-                       if (len == (uint64_t)-1) {
-                               qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
-                               ret = -QPACK_RET_TRUNCATED;
-                               goto out;
-                       }
-
-                       if (len < length) {
+                       if (len == (uint64_t)-1 || len < length) {
                                qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
                                ret = -QPACK_RET_TRUNCATED;
                                goto out;
@@ -451,6 +445,7 @@ int qpack_decode_fs(const unsigned char *raw, uint64_t len, struct buffer *tmp,
                                        ret = -QPACK_RET_TOO_LARGE;
                                        goto out;
                                }
+
                                nlen = huff_dec(raw, length, trash, tmp->size - tmp->data);
                                if (nlen == (uint32_t)-1) {
                                        qpack_debug_printf(stderr, " can't decode huffman.\n");
@@ -467,12 +462,6 @@ int qpack_decode_fs(const unsigned char *raw, uint64_t len, struct buffer *tmp,
                                value = ist2(raw, length);
                        }
 
-                       if (len < length) {
-                               qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
-                               ret = -QPACK_RET_TRUNCATED;
-                               goto out;
-                       }
-
                        raw += length;
                        len -= length;
                }
@@ -485,7 +474,7 @@ int qpack_decode_fs(const unsigned char *raw, uint64_t len, struct buffer *tmp,
                        n = *raw & 0x10;
                        hname = *raw & 0x08;
                        name_len = qpack_get_varint(&raw, &len, 3);
-                       if (len == (uint64_t)-1) {
+                       if (len == (uint64_t)-1 || len < name_len) {
                                qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
                                ret = -QPACK_RET_TRUNCATED;
                                goto out;
@@ -494,12 +483,6 @@ int qpack_decode_fs(const unsigned char *raw, uint64_t len, struct buffer *tmp,
                        qpack_debug_printf(stderr, " n=%d hname=%d name_len=%llu", !!n, !!hname, (unsigned long long)name_len);
                        /* Name string */
 
-                       if (len < name_len) {
-                               qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
-                               ret = -QPACK_RET_TRUNCATED;
-                               goto out;
-                       }
-
                        if (hname) {
                                char *trash;
                                int nlen;
@@ -531,7 +514,7 @@ int qpack_decode_fs(const unsigned char *raw, uint64_t len, struct buffer *tmp,
 
                        hvalue = *raw & 0x80;
                        value_len = qpack_get_varint(&raw, &len, 7);
-                       if (len == (uint64_t)-1) {
+                       if (len == (uint64_t)-1 || len < value_len) {
                                qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
                                ret = -QPACK_RET_TRUNCATED;
                                goto out;
@@ -539,12 +522,6 @@ int qpack_decode_fs(const unsigned char *raw, uint64_t len, struct buffer *tmp,
 
                        qpack_debug_printf(stderr, " hvalue=%d value_len=%llu", !!hvalue, (unsigned long long)value_len);
 
-                       if (len < value_len) {
-                               qpack_debug_printf(stderr, "##ERR@%d\n", __LINE__);
-                               ret = -QPACK_RET_TRUNCATED;
-                               goto out;
-                       }
-
                        if (hvalue) {
                                char *trash;
                                int nlen;