From 96e04dd8cf38ed0473e3ceebb0d77b95e38e569c Mon Sep 17 00:00:00 2001 From: Chema Gonzalez Date: Wed, 27 Dec 2023 15:17:54 -0800 Subject: [PATCH] Y4M loader: add error messages on parsing errors Tested: Image with 420p10 color space. Before: ``` $ IMLIB2_DEBUG=31:0 imlib2_view out.y4m ... LOAD: __imlib_FindBestLoader: fmt='y4m': /usr/local/lib/imlib2/loaders/y4m.so IMG : __imlib_LoadImageWrapper: fmt='y4m' file='out.y4m'(out.y4m) frame=1, imm=1 IMG : __imlib_LoadImageWrapper: y4m : out.y4m: Elapsed time: 0.010 ms ... ``` After: ``` $ IMLIB2_DEBUG=31:0 imlib2_view out.y4m ... LOAD: __imlib_FindBestLoader: fmt='y4m': /usr/local/lib/imlib2/loaders/y4m.so IMG : __imlib_LoadImageWrapper: fmt='y4m' file='out.y4m'(out.y4m) frame=1, imm=1 LDR-y4m: y4m__parse_params: unknown C: 'C420p10' IMG : __imlib_LoadImageWrapper: y4m : out.y4m: Elapsed time: 0.010 ms ... ``` --- src/modules/loaders/loader_y4m.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/modules/loaders/loader_y4m.c b/src/modules/loaders/loader_y4m.c index 336f1f9..5612b42 100644 --- a/src/modules/loaders/loader_y4m.c +++ b/src/modules/loaders/loader_y4m.c @@ -171,6 +171,9 @@ y4m__parse_params(Y4mParse * res, const uint8_t ** start, const uint8_t * end) if (rate_num == rate_den) { res->fps = Y4M_PARSE_FPS_1; } else { + char str[1024]; + sscanf((char *)(p-1), "%s", (char *)&str); + D("%s: unknown frame rate: '%s'\n", __func__, str); res->fps = Y4M_PARSE_FPS_OTHER; } } @@ -184,8 +187,12 @@ y4m__parse_params(Y4mParse * res, const uint8_t ** start, const uint8_t * end) res->interlacing = Y4M_PARSE_IL_BOTTOM; else if (y4m__match("m", 1, &p, end)) res->interlacing = Y4M_PARSE_IL_MIXED; - else + else { + char str[1024]; + sscanf((char *)(p-1), "%s", (char *)&str); + D("%s: unknown interlace type: '%s'\n", __func__, str); return Y4M_PARSE_CORRUPTED; + } break; case 'C': if (y4m__match("mono", 4, &p, end)) @@ -202,8 +209,12 @@ y4m__parse_params(Y4mParse * res, const uint8_t ** start, const uint8_t * end) res->colour_space = Y4M_PARSE_CS_422; else if (y4m__match("444 ", 4, &p, end)) res->colour_space = Y4M_PARSE_CS_444; - else + else { + char str[1024]; + sscanf((char *)(p-1), "%s", (char *)&str); + D("%s: unknown color type: '%s'\n", __func__, str); return Y4M_PARSE_CORRUPTED; + } break; case 'A': if (y4m__match("0:0", 3, &p, end))