[RFC 7541] 5.1. Integer representation
| 61 | // [RFC 7541] 5.1. Integer representation |
| 62 | // |
| 63 | int64_t |
| 64 | xpack_decode_integer(uint64_t &dst, const uint8_t *buf_start, const uint8_t *buf_end, uint8_t n) |
| 65 | { |
| 66 | if (buf_start >= buf_end) { |
| 67 | return XPACK_ERROR_COMPRESSION_ERROR; |
| 68 | } |
| 69 | |
| 70 | const uint8_t *p = buf_start; |
| 71 | |
| 72 | dst = (*p & ((1 << n) - 1)); |
| 73 | if (dst == static_cast<uint64_t>(1 << n) - 1) { |
| 74 | int m = 0; |
| 75 | do { |
| 76 | if (++p >= buf_end) { |
| 77 | return XPACK_ERROR_COMPRESSION_ERROR; |
| 78 | } |
| 79 | |
| 80 | uint64_t added_value = *p & 0x7f; |
| 81 | if ((UINT64_MAX >> m) < added_value) { |
| 82 | // Excessively large integer encodings - in value or octet |
| 83 | // length - MUST be treated as a decoding error. |
| 84 | return XPACK_ERROR_COMPRESSION_ERROR; |
| 85 | } |
| 86 | dst += added_value << m; |
| 87 | m += 7; |
| 88 | } while (*p & 0x80); |
| 89 | } |
| 90 | |
| 91 | return p - buf_start + 1; |
| 92 | } |
| 93 | |
| 94 | // |
| 95 | // [RFC 7541] 5.2. String Literal Representation |
no outgoing calls
no test coverage detected