Skip to content

File Offset Calculation Assertion Failure #4343

@gaborbernat

Description

@gaborbernat

Universal Ctags crashes with assertion failure in getInputFileOffsetForLine at main/read.c:421 when the file offset calculation returns a negative value. The assertion r >= 0 fails due to issues with how ctags calculates file positions, particularly with files that have unusual line endings or specific content patterns. Note, for this to crash the binary you need to run in debug mode.

Reproduced by:

# Create simple HTML file that triggers the offset calculation bug
printf '<body><p>Hi</p>\r\n' > offset_crash.html

# This crashes with: getInputFileOffsetForLine: Assertion `r >= 0' failed
./ctags -o /tmp/test offset_crash.html

Suggested fix: Add bounds checking in the file offset calculation logic. The function should validate that calculated offsets are non-negative and handle edge cases where file position calculations might underflow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions