AttributeError Vulnerabilities in convert.py
Describe the bug
Two AttributeError vulnerabilities exist in scripts/convert.py where string methods are called on potentially None values without type checking:
- Line 815:
if k.strip() not in el_text:- Calls.strip()on keykwithout verifying it's a string - Line 894:
if convert_vars.args.layout.lower() == "all"- Calls.lower()onargs.layoutwithout null checking
These conditions will crash the script with AttributeError: 'NoneType' object has no attribute 'strip'/'lower' when the variables contain None values.
Expected behavior
The script should handle None values gracefully without crashing. String methods should only be called after verifying the variable is actually a string, or None values should be handled appropriately.
Desktop (please complete the following information)
- OS: All operating systems (Windows, Linux, macOS)
- Python Version: All versions supporting the codebase
- Script Version: Current main branch
Additional context
Line 815 vulnerability scenario:
- Occurs when
replacement_valuescontains None keys from malformed YAML data - YAML files with
nullkeys (using~ornullsyntax) can cause this - Example problematic YAML:
data:
~: "value with null key" # Creates None key
Line 894 vulnerability scenario:
- Occurs if
convert_vars.args.layoutis manually set to None - Cannot happen through normal argparse usage (defaults are strings)
- Can occur during debugging, testing, or if args are modified by other code
Impact:
- Script crashes with AttributeError
- Prevents document generation
- Affects robustness when processing user-provided or potentially corrupted data
Proposed fixes:
- Line 815:
if isinstance(k, str) and k.strip() not in el_text: - Line 894:
if convert_vars.args.layout and convert_vars.args.layout.lower() == "all" or convert_vars.args.layout == ""
These fixes maintain existing functionality while adding defensive programming against edge cases.
I have assigned you.