Copilot commented on code in PR #3462:
URL: https://github.com/apache/brpc/pull/3462#discussion_r3794939296


##########
src/brpc/details/hpack.cpp:
##########
@@ -223,9 +223,13 @@ int IndexTable::Init(const IndexTableOptions& options) {
         num_headers = options.static_table_size;
         _max_size = UINT_MAX;
     } else {
-        num_headers = options.max_size / (32 + 2);
+        num_headers = options.max_size / (32 + 1);

Review Comment:
   `num_headers` can become 0 when `options.max_size < 33` (including the valid 
`max_size == 0` case to disable the dynamic table). With the current code, that 
leads to `malloc(0)` and `IndexTable::Init` may fail on platforms where 
`malloc(0)` returns NULL, making `HPacker::Init(0)` nondeterministically fail 
even though the table can be empty safely. Consider clamping `num_headers` to 
at least 1 before allocating/initializing the queue (entries still won’t be 
added because `entry_size > _max_size`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to