Repository navigation
XPM: Allow / in array name - #58
akashchamp wants to merge 1 commit into
Conversation
|
I generally don't like increasing lookahead (which will be expensive when parsing large images) just for the specific edge case that we see now in #57; I wouldn't be surprised if there are other files that deviate from being correct in strange ways, because historical parsers (see comment in #57 (comment)) would accept most anything. It may be quite a big change, but I think explicitly introducing a As for which of the many mutually incompatible header parsing approaches to use... I think getting closer to libxpm's behavior (see #57 (comment)) is least likely to break on historical/hand written images. |
Some tools write the source file path as the array name, e.g.
`static char */tmp/K9Duvy1kRf/page-001[] = {`. Instead of parsing the
declaration, skip everything after `/* XPM */` up to the first string,
honoring C comments, as libXpm does.
Fixes image-rs#57
93bbf4c to
f919e55
Compare
|
Thanks, I reworked this to follow libXpm's header handling: after the |
Fixes #57.
Some tools write the source file path as the array name (
static char */tmp/K9Duvy1kRf/page-001[] = {), which failed with "Failed to parse array definition" because the/was taken as the start of a comment.This now follows libXpm's header handling instead of parsing the C declaration. In
xpmParseHeader(src/data.c), libXpm only checks that the second word of the first line isXPM(for XPM 3), then callsxpmNextStringwith"as the string start, which skips everything up to the first"; a/followed by*starts a comment (ParseComment) that is skipped up to*/, so a"inside a comment does not count. The declaration itself (static,const,char,*, the name,[] = {) is never looked at.Here the
/* XPM */check is unchanged, andskip_to_first_stringreplaces the declaration parsing: it skips to the first"with the same comment handling, using the existing one byte of lookahead.read_keyword,read_name,read_to_newlineandskip_non_empty_whitespace_and_commentswere only used by the old declaration parsing and are removed. The rest of the decoder is unchanged, and the module docs no longer liststatic char ** name = {as rejected. Files are still rejected if the first line is not/* XPM */or if there is no string before EOF outside a comment.Added
tests/images/xpm/green_slash_name.xpm(green.xpmwith the header line from the issue, same reference PNG) and unit tests for a/in the name, a comment containing"inside the name, and the rejected headers above.Checked with:
cargo test: the new fixture and the slash/comment unit tests fail onmain(the fixture with the exact error from the issue,byte=24,line=2:col=14) and pass with this change; the existing XPM test images still match their reference PNGscargo clippy --all-features --all-targets -- -D warningsandcargo fmt --checkcargo run --example convert -- tests/images/xpm/green_slash_name.xpm out.pngwrites the 5x5 PNG