How can you discern a valid filename from a malicious one in a generic way?
I probably couldn't.
I actually haven't seen an attack through malicious filenames in 20 years.
*knock on wood*
The olden days war story goes along the lines of files containing unix brand conforming line breaks followed by commands. Those were aimed at the habit of some superuser types using scripts with xargs(1) for file system tidyup tasks or such and ending up with unwanted command execution. I find I don't remember that very well.
Generally I'd prefer my file names to contain [\w.-] exclusively... the world out there please hear my wishful plea :-)
(hooked on the Perl Programming language)