Skip to content

Fix crash in TinyTagEditor::runAction() with files without extensions - #652

Merged
arybczak merged 1 commit into
ncmpcpp:masterfrom
hyder365:fix/substr-npos-crash
Jun 25, 2026
Merged

arybczak merged 1 commit into
ncmpcpp:masterfrom
hyder365:fix/substr-npos-crash

Conversation

@hyder365

Copy link
Copy Markdown
Contributor

When a user opens the Tiny Tag Editor for a song without a file extension and selects the "Filename" option (option 20), ncmpcpp crashes.

The issue occurs in the code that splits the filename into a base name and extension:

size_t dot = filename.rfind(".");
std::string extension = filename.substr(dot);  // CRASH if dot == npos
filename = filename.substr(0, dot);             // OK - npos returns whole string

If the filename doesn't contain a '.', rfind(".") returns std::string::npos, and calling substr(npos) throws std::out_of_range, causing the crash. This affects files without extensions and stream URIs.

The fix checks if dot != std::string::npos before attempting to extract the extension:

std::string extension;
if (dot != std::string::npos)
{
    extension = filename.substr(dot);
    filename = filename.substr(0, dot);
}

@arybczak
arybczak merged commit cb9c8df into ncmpcpp:master Jun 25, 2026
@arybczak

Copy link
Copy Markdown
Collaborator

Thanks :)

kda pushed a commit to kda/ncmpcpp that referenced this pull request Sep 8, 2026
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