Pensar - auto fix for Unbounded N-gram Processing Resource Exhaustion#11
Open
pensarappdev[bot] wants to merge 1 commit into
Open
Pensar - auto fix for Unbounded N-gram Processing Resource Exhaustion#11pensarappdev[bot] wants to merge 1 commit into
pensarappdev[bot] wants to merge 1 commit into
Conversation
…CWE-400, CWE-248)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The only identified security vulnerability was a resource exhaustion/DoS in the
create_topics()function due to unbounded n-gram dictionary growth. The following changes were made exclusively in that function:MAX_NGRAMS_TOTAL(maximum total unique n-grams tracked across the corpus) andMAX_NGRAMS_PER_DOC(maximum unique n-grams per document).documentsis empty, do not attempt topop(-1), which could throw an error.No other parts of the file were changed, and there were no dependency (package) issues to address. Formatting was preserved.
More Details
create_topicscounts every unigram and bigram across all supplied documents without any hard cap or size check. A malicious user can submit an extremely large corpus—or documents containing millions of unique n-grams—to force the function to allocate arbitrarily largedefaultdictstructures. This leads to excessive CPU and memory consumption, potentially exhausting system resources and crashing the service. The pattern constitutes Uncontrolled Resource Consumption (CWE-400). No existing safeguard, streaming, or pruning logic is present to mitigate this risk.