Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential Infinite loop in evict_to_internal function #2306

Closed
KershawChang opened this issue Jan 2, 2025 · 1 comment · Fixed by #2307
Closed

Potential Infinite loop in evict_to_internal function #2306

KershawChang opened this issue Jan 2, 2025 · 1 comment · Fixed by #2307

Comments

@KershawChang
Copy link
Collaborator

See bug 1939690 comment 4.

I've asked the reporter to provide STR. It's still not clear how easy this can be triggered.

@mxinden
Copy link
Collaborator

mxinden commented Jan 2, 2025

The reporter on Bugzilla is hinting at this code:

pub fn evict_to_internal(&mut self, reduce: u64, only_check: bool) -> bool {
qtrace!(
[self],
"reduce table to {}, currently used:{} only_check:{}",
reduce,
self.used,
only_check
);
let mut used = self.used;
while (!self.dynamic.is_empty()) && used > reduce {
if let Some(e) = self.dynamic.back() {
if !e.can_reduce(self.acked_inserts_cnt) {
return false;
}
used -= u64::try_from(e.size()).unwrap();
if !only_check {
self.used -= u64::try_from(e.size()).unwrap();
self.dynamic.pop_back();
}
}
}
true
}

Off the top of my head I see the following scenario:

  • only_check is true
  • self.dyamic.is_empty() is false
  • e.can_reduce() is true

This would lead to infinite many unnecessary loop iterations.

The following should fix the issue:

diff --git a/neqo-qpack/src/table.rs b/neqo-qpack/src/table.rs
index 8c8b8d5e..abea8be2 100644
--- a/neqo-qpack/src/table.rs
+++ b/neqo-qpack/src/table.rs
@@ -260,6 +260,7 @@ impl HeaderTable {
         self.evict_to_internal(reduce, true)
     }
 
     pub fn evict_to_internal(&mut self, reduce: u64, only_check: bool) -> bool {
         qtrace!(
             [self],
@@ -278,6 +279,8 @@ impl HeaderTable {
                 if !only_check {
                     self.used -= u64::try_from(e.size()).unwrap();
                     self.dynamic.pop_back();
+                } else {
+                    return true;
                 }
             }
         }

I will give this more thought and try to reproduce it in a unit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants