XMem icon indicating copy to clipboard operation
XMem copied to clipboard

[Bug] Add Missing Payload Range Checks and Empty String Validation in Text Utilities

Open vakrahul opened this issue 5 months ago • 2 comments

Context & Problem

In src/utils/text.py and across our text pre-processing hooks, strings are parsed and prepared for memory ingestion. Currently, these helper methods do not strictly validate bounds on inbound string objects.

If an upstream pipeline mistakenly forwards an empty payload "" or an anomalously massive un-chunked string block, the processing utility functions execution loops unnecessarily, wasting resources before passing the payload to downstream validation schemas.

Proposed Solution

Add explicit, lightweight guard clauses at the entry points of our string helper functions to catch edge cases early.

Key Implementation Steps

  • Empty Checking: Add an immediate guard clause to return early if not text.strip() is evaluated.
  • Length Constraints: Implement a reasonable maximum length threshold verification check to log an explicit warning or throw a descriptive value error early if the string size goes out of normal programmatic boundaries.
  • Unit Tests: Add a quick series of unit test assertions inside tests/unit/test_utils.py covering null, empty, and boundary conditions to ensure zero regressions.

Impacted Files

  • src/utils/text.py
  • tests/unit/test_utils.py

vakrahul avatar Jun 03 '26 09:06 vakrahul

@ishaanxgupta

vakrahul avatar Jun 03 '26 09:06 vakrahul

feel free to raise a PR

ishaanxgupta avatar Jun 03 '26 10:06 ishaanxgupta