After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 748604 - local-metadata: Don't crash on files named wsb.wmv
local-metadata: Don't crash on files named wsb.wmv
Status: RESOLVED FIXED
Product: grilo
Classification: Other
Component: plugins
git master
Other Linux
: Normal blocker
: ---
Assigned To: grilo-maint
grilo-maint
Depends on:
Blocks:
 
 
Reported: 2015-04-28 23:47 UTC by Olivier Crête
Modified: 2015-06-11 11:13 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
local-metadata: Ignore sanitization if the whole filename is blacklisted (1.18 KB, patch)
2015-04-28 23:47 UTC, Olivier Crête
committed Details | Review
tests: Add a test for video_sanitise_string() crasher (1.01 KB, patch)
2015-04-29 11:20 UTC, Bastien Nocera
committed Details | Review
tests: Add another test for a video_sanitise_string() (1.07 KB, patch)
2015-05-19 19:23 UTC, Jan Alexander Steffens (heftig)
committed Details | Review
local-metadata: Fixes to video_sanitise_string non-alnum handling (2.30 KB, patch)
2015-05-19 19:24 UTC, Jan Alexander Steffens (heftig)
committed Details | Review
Remove uppercase versions of blacklisted words (1.08 KB, patch)
2015-06-11 06:42 UTC, Alberto Garcia
committed Details | Review

Description Olivier Crête 2015-04-28 23:47:36 UTC
If you have a file named wsb.wmv, grilo just crashes, taking totem down with it.
Comment 1 Olivier Crête 2015-04-28 23:47:55 UTC
Created attachment 302535 [details] [review]
local-metadata: Ignore sanitization if the whole filename is blacklisted

If the whole filename ends up blacklisted, then just take it as-is.
Comment 2 Bastien Nocera 2015-04-29 08:25:45 UTC
Comment on attachment 302535 [details] [review]
local-metadata: Ignore sanitization if the whole filename is blacklisted

Looks good, thanks!
Comment 3 Bastien Nocera 2015-04-29 11:20:40 UTC
Created attachment 302554 [details] [review]
tests: Add a test for video_sanitise_string() crasher
Comment 4 Bastien Nocera 2015-04-29 11:22:12 UTC
Attachment 302535 [details] pushed as 85fc7cb - local-metadata: Ignore sanitization if the whole filename is blacklisted
Attachment 302554 [details] pushed as 34cf295 - tests: Add a test for video_sanitise_string() crasher
Comment 5 Jan Alexander Steffens (heftig) 2015-05-19 18:50:53 UTC
Alas, this is not yet fixed. See https://bugs.archlinux.org/task/44724 (0.2.14-3 is 0.2.14 with the patch from attachment 302535 [details] [review]).

Seems that line_end can become null after subsequent g_utf8_find_prev_char?

I also noticed that g_unichar_isalnum is used on a utf-8 gchar instead of a gunichar. Seems terribly wrong to me.

I'm currently patching the code.
Comment 6 Jan Alexander Steffens (heftig) 2015-05-19 19:23:22 UTC
Created attachment 303618 [details] [review]
tests: Add another test for a video_sanitise_string()

Adds a failing test using the crashing file name from the Arch bug.
Comment 7 Jan Alexander Steffens (heftig) 2015-05-19 19:24:35 UTC
Created attachment 303619 [details] [review]
local-metadata: Fixes to video_sanitise_string non-alnum handling

- Extract loop condition into a helper function
- Use g_utf8_get_char to properly convert to unichar
- Be more defensive about g_utf8_find_prev_char returning NULL
Comment 8 Alberto Garcia 2015-06-10 09:16:11 UTC
I would like to include these patches in the Debian packages, but I would like to have the last one by Jan Alexander Steffens reviewed first, otherwise grilo-plugins is still crashing.

Bastian, is that patch fine? Thanks!
Comment 9 Bastien Nocera 2015-06-10 09:21:09 UTC
Review of attachment 303619 [details] [review]:

::: src/local-metadata/grl-local-metadata.c
@@ +248,3 @@
+  gunichar uchar;
+
+  if (str == NULL) {

No need for braces for one-line conditionals.

@@ +254,3 @@
+  uchar = g_utf8_get_char (str);
+
+  if (g_unichar_isalnum (uchar)) {

Ditto.

@@ +258,3 @@
+  }
+
+  if (uchar == '!' || uchar == '?' || uchar == '.') {

Ditto.
Comment 10 Bastien Nocera 2015-06-10 09:34:57 UTC
Review of attachment 303618 [details] [review]:

This looks fine, but I can't make that crash...

I'm fine with fixing "breaks with non-ASCII UTF-8" bugs, but a test case should fail before the patch is applied, otherwise the point is moot.
Comment 11 Alberto Garcia 2015-06-10 09:39:19 UTC
(In reply to Bastien Nocera from comment #10)
> Review of attachment 303618 [details] [review] [review]:
>
> This looks fine, but I can't make that crash...

Thanks for the quick review!

I can make it crash if I try to open a file named [XVID-ITA].avi from
totem.
Comment 12 Bastien Nocera 2015-06-10 09:49:41 UTC
(In reply to Alberto Garcia from comment #11)
> (In reply to Bastien Nocera from comment #10)
> > Review of attachment 303618 [details] [review] [review] [review]:
> >
> > This looks fine, but I can't make that crash...
> 
> Thanks for the quick review!
> 
> I can make it crash if I try to open a file named [XVID-ITA].avi from
> totem.

With current grilo-plugins master? (which means one with Olivier's patch, but not Jan Alexander's).

Are you using 32-bit or 64-bit system? What's the backtrace of that crash?
Comment 13 Alberto Garcia 2015-06-10 11:00:58 UTC
(In reply to Bastien Nocera from comment #12)
> > I can make it crash if I try to open a file named [XVID-ITA].avi
> > from totem.

> With current grilo-plugins master? (which means one with Olivier's
> patch, but not Jan Alexander's).

No, this is 0.2.14 + Olivier's patch, on a 64-bit system.

It looks like no one's checking if this is non-NULL:

     line_end = g_utf8_find_prev_char (line, line_end);

Program received signal SIGSEGV, Segmentation fault.
0x00007fffc48c04f8 in video_sanitise_string (str=0x5555580ad9e0 "[XVID-ITA]") at grl-local-metadata.c:284
1: line = (gchar *) 0x5555580ad9e0 "[XVID-ITA]"
2: line_end = (gchar *) 0x0

(gdb) bt
  • #0 video_sanitise_string
    at grl-local-metadata.c line 284
  • #1 video_display_name_to_metadata
    at grl-local-metadata.c line 316
  • #2 video_guess_values_from_display_name
    at grl-local-metadata.c line 334
  • #3 resolve_video
  • #4 grl_local_metadata_source_resolve
    at grl-local-metadata.c line 1060

Comment 14 Jan Alexander Steffens (heftig) 2015-06-10 17:18:05 UTC
Perhaps prev_char had a bug that got resolved on master?
Comment 15 Alberto Garcia 2015-06-11 06:42:58 UTC
Created attachment 305047 [details] [review]
Remove uppercase versions of blacklisted words

I haven't seen any relevant changes in master since 0.2.14.

I checked a bit the code of this function, though:

 - The input string is "[XVID-ITA]".
 - After checking the list of blacklisted words, line_end is "XVID-ITA]" ("xvid" is blacklisted).
 - Then there's line_end = g_utf8_find_prev_char(), so line_end becomes "[XVID-ITA]"

After that the loop search backwards for the first alphanumeric
char. Since we're at the beginning of the string already there's
nothing to search, line_end becomes null and the process crashes.

Jan's patch solves the crash because it checkes for null in every
iteration of the loop.

On a related note, the list of blacklisted words is matched using
strcasestr(), so I don't see the point of having the same strings in
both uppercase and lowercase.
Comment 16 Bastien Nocera 2015-06-11 11:13:44 UTC
All pushed to master. Just to note that the lua source that implements that functionality carries on working ;)