[tracker-miners/sam/blocklist-dds: 1/2] Allow blocklisting certain MIME types in tracker-extract rules
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/blocklist-dds: 1/2] Allow blocklisting certain MIME types in tracker-extract rules
- Date: Sun, 3 Nov 2019 17:21:54 +0000 (UTC)
commit 032004c1dfdae4f31b37bb9bd659e1f10343f8cc
Author: Sam Thursfield <sam afuera me uk>
Date: Sun Nov 3 18:12:13 2019 +0100
Allow blocklisting certain MIME types in tracker-extract rules
The initial use case for this is solving
https://gitlab.gnome.org/GNOME/tracker/issues/158 -- we need to block
.dds files from being extracted, as they can trigger arbitrary incorrect
codepaths in GStreamer that sometimes cause Linux to hang.
src/libtracker-extract/tracker-module-manager.c | 48 ++++++++++++++++------
.../test-extract-rules/90-image-generic.rule | 3 +-
.../tracker-module-manager-test.c | 4 ++
3 files changed, 42 insertions(+), 13 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-module-manager.c b/src/libtracker-extract/tracker-module-manager.c
index 426cfb385..b0b6e2b43 100644
--- a/src/libtracker-extract/tracker-module-manager.c
+++ b/src/libtracker-extract/tracker-module-manager.c
@@ -30,7 +30,8 @@
typedef struct {
const gchar *rule_path;
const gchar *module_path; /* intern string */
- GList *patterns;
+ GList *allow_patterns;
+ GList *block_patterns;
GStrv fallback_rdf_types;
} RuleInfo;
@@ -71,8 +72,8 @@ load_extractor_rule (GKeyFile *key_file,
GError **error)
{
GError *local_error = NULL;
- gchar *module_path, **mimetypes;
- gsize n_mimetypes, i;
+ gchar *module_path, **allow_mimetypes, **block_mimetypes;
+ gsize n_allow_mimetypes, n_block_mimetypes, i;
RuleInfo rule = { 0 };
module_path = g_key_file_get_string (key_file, "ExtractorRule", "ModulePath", &local_error);
@@ -104,9 +105,9 @@ load_extractor_rule (GKeyFile *key_file,
module_path = tmp;
}
- mimetypes = g_key_file_get_string_list (key_file, "ExtractorRule", "MimeTypes", &n_mimetypes,
&local_error);
+ allow_mimetypes = g_key_file_get_string_list (key_file, "ExtractorRule", "MimeTypes",
&n_allow_mimetypes, &local_error);
- if (!mimetypes) {
+ if (!allow_mimetypes) {
g_free (module_path);
if (local_error) {
@@ -116,6 +117,9 @@ load_extractor_rule (GKeyFile *key_file,
return FALSE;
}
+ /* This key is optional */
+ block_mimetypes = g_key_file_get_string_list (key_file, "ExtractorRule", "BlockMimeTypes",
&n_block_mimetypes, &local_error);
+
rule.rule_path = g_strdup (rule_path);
rule.fallback_rdf_types = g_key_file_get_string_list (key_file, "ExtractorRule", "FallbackRdfTypes",
NULL, NULL);
@@ -123,15 +127,23 @@ load_extractor_rule (GKeyFile *key_file,
/* Construct the rule */
rule.module_path = g_intern_string (module_path);
- for (i = 0; i < n_mimetypes; i++) {
+ for (i = 0; i < n_allow_mimetypes; i++) {
+ GPatternSpec *pattern;
+
+ pattern = g_pattern_spec_new (allow_mimetypes[i]);
+ rule.allow_patterns = g_list_prepend (rule.allow_patterns, pattern);
+ }
+
+ for (i = 0; i < n_block_mimetypes; i++) {
GPatternSpec *pattern;
- pattern = g_pattern_spec_new (mimetypes[i]);
- rule.patterns = g_list_prepend (rule.patterns, pattern);
+ pattern = g_pattern_spec_new (block_mimetypes[i]);
+ rule.block_patterns = g_list_prepend (rule.block_patterns, pattern);
}
g_array_append_val (rules, rule);
- g_strfreev (mimetypes);
+ g_strfreev (allow_mimetypes);
+ g_strfreev (block_mimetypes);
g_free (module_path);
return TRUE;
@@ -245,15 +257,27 @@ lookup_rules (const gchar *mimetype)
/* Apply the rules! */
for (i = 0; i < rules->len; i++) {
GList *l;
+ gboolean matched_allow_pattern = FALSE, matched_block_pattern = FALSE;
info = &g_array_index (rules, RuleInfo, i);
- for (l = info->patterns; l; l = l->next) {
+ for (l = info->allow_patterns; l; l = l->next) {
if (g_pattern_match (l->data, len, mimetype, reversed)) {
- /* Match, store for future queries and return */
- mimetype_rules = g_list_prepend (mimetype_rules, info);
+ matched_allow_pattern = TRUE;
+ break;
}
}
+
+ for (l = info->block_patterns; l; l = l->next) {
+ if (g_pattern_match (l->data, len, mimetype, reversed)) {
+ matched_block_pattern = TRUE;
+ break;
+ }
+ }
+
+ if (matched_allow_pattern && !matched_block_pattern) {
+ mimetype_rules = g_list_prepend (mimetype_rules, info);
+ };
}
if (mimetype_rules) {
diff --git a/tests/libtracker-extract/test-extract-rules/90-image-generic.rule
b/tests/libtracker-extract/test-extract-rules/90-image-generic.rule
index 642c3e0da..e34c6b3dc 100644
--- a/tests/libtracker-extract/test-extract-rules/90-image-generic.rule
+++ b/tests/libtracker-extract/test-extract-rules/90-image-generic.rule
@@ -1,4 +1,5 @@
[ExtractorRule]
-ModulePath=libextract-gstreamer.so
+ModulePath=TEST_MODULE_IMAGE
MimeTypes=image/*;
+BlockMimeTypes=image/x-blocked;
FallbackRdfTypes=nfo:Image;nmm:Photo;
diff --git a/tests/libtracker-extract/tracker-module-manager-test.c
b/tests/libtracker-extract/tracker-module-manager-test.c
index ffd2a39b2..992f6ee75 100644
--- a/tests/libtracker-extract/tracker-module-manager-test.c
+++ b/tests/libtracker-extract/tracker-module-manager-test.c
@@ -67,6 +67,10 @@ test_extract_rules (void)
// No rule should match this.
l = tracker_extract_module_manager_get_matching_rules("text/generic");
g_assert_cmpint (g_list_length (l), ==, 0);
+
+ // The image/x-blocked MIME type is explicitly blocked, so no rule should match.
+ l = tracker_extract_module_manager_get_matching_rules("image/x-blocked");
+ g_assert_cmpint (g_list_length (l), ==, 0);
}
int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]