Skip to content

BUG: Fix IndexError on empty string in ArrayObject._to_lst#3784

Open
Abzaek wants to merge 1 commit into
py-pdf:mainfrom
Abzaek:fix/array-empty-string-crash
Open

BUG: Fix IndexError on empty string in ArrayObject._to_lst#3784
Abzaek wants to merge 1 commit into
py-pdf:mainfrom
Abzaek:fix/array-empty-string-crash

Conversation

@Abzaek
Copy link
Copy Markdown
Contributor

@Abzaek Abzaek commented May 16, 2026

Problem

ArrayObject._to_lst() tested lst[0] == "/" to decide whether to create a NameObject or TextStringObject. When lst is the empty string "", this raises IndexError: string index out of range.

This crashes arr + "", arr += "", and arr -= "".

Fix

Replace lst[0] == "/" with lst.startswith("/"). "".startswith("/") returns False, falling through to TextStringObject("") as expected. Behavior is identical for all non-empty strings.

lst[0] raises IndexError when lst is the empty string ''.
Replace with lst.startswith('/') which returns False for '',
falling through to TextStringObject('') as expected.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.64%. Comparing base (8c03dc4) to head (9ce1402).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3784   +/-   ##
=======================================
  Coverage   97.64%   97.64%           
=======================================
  Files          55       55           
  Lines       10291    10291           
  Branches     1890     1890           
=======================================
  Hits        10049    10049           
  Misses        137      137           
  Partials      105      105           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Is there are real-world example where this could be observed?

Additionally, please provide a corresponding 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 this pull request may close these issues.

2 participants