Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tumbler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xfce
tumbler
Commits
a0fc191e
Commit
a0fc191e
authored
2 years ago
by
Gaël Bonithon
Browse files
Options
Downloads
Patches
Plain Diff
gst-thumbnailer: Add mime type check (Fixes
#65
)
parent
1719ce1a
No related branches found
No related tags found
No related merge requests found
Pipeline
#16592
passed
2 years ago
Stage: build
Stage: distcheck
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/gst-thumbnailer/gst-thumbnailer.c
+50
-0
50 additions, 0 deletions
plugins/gst-thumbnailer/gst-thumbnailer.c
with
50 additions
and
0 deletions
plugins/gst-thumbnailer/gst-thumbnailer.c
+
50
−
0
View file @
a0fc191e
...
...
@@ -40,6 +40,7 @@
#define GUESS_BUFFER_SIZE 512
#define BORING_IMAGE_VARIANCE 256.0
/* tweak this if necessary */
#define TUMBLER_GST_PLAY_FLAG_VIDEO (1 << 0)
/* from GstPlayFlags */
#define TUMBLER_GST_PLAY_FLAG_AUDIO (1 << 1)
/* from GstPlayFlags */
...
...
@@ -530,6 +531,12 @@ gst_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
TumblerThumbnailFlavor
*
flavor
;
GdkPixbuf
*
scaled
;
const
gchar
*
uri
;
GFile
*
file
;
GFileInputStream
*
stream
;
guchar
buffer
[
GUESS_BUFFER_SIZE
];
gssize
size
;
gchar
*
guessed_type
,
*
claimed_type
;
gboolean
uncertain
,
equals
;
/* check for early cancellation */
if
(
g_cancellable_is_cancelled
(
cancellable
))
...
...
@@ -553,6 +560,49 @@ gst_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
return
;
}
/* check if real mime type matches advertised mime type to avoid server-side request
* forgery: see https://gitlab.xfce.org/xfce/tumbler/-/issues/65 */
file
=
g_file_new_for_uri
(
uri
);
stream
=
g_file_read
(
file
,
cancellable
,
&
error
);
g_object_unref
(
file
);
if
(
stream
==
NULL
)
{
g_signal_emit_by_name
(
thumbnailer
,
"error"
,
uri
,
error
->
domain
,
error
->
code
,
error
->
message
);
g_error_free
(
error
);
return
;
}
size
=
g_input_stream_read
(
G_INPUT_STREAM
(
stream
),
buffer
,
GUESS_BUFFER_SIZE
,
cancellable
,
&
error
);
g_object_unref
(
stream
);
if
(
size
==
-
1
)
{
g_signal_emit_by_name
(
thumbnailer
,
"error"
,
uri
,
error
->
domain
,
error
->
code
,
error
->
message
);
g_error_free
(
error
);
return
;
}
guessed_type
=
g_content_type_guess
(
NULL
,
buffer
,
size
,
&
uncertain
);
claimed_type
=
g_content_type_from_mime_type
(
tumbler_file_info_get_mime_type
(
info
));
equals
=
guessed_type
!=
NULL
&&
claimed_type
!=
NULL
&&
g_content_type_equals
(
guessed_type
,
claimed_type
);
g_free
(
guessed_type
);
g_free
(
claimed_type
);
if
(
uncertain
||
!
equals
)
{
g_set_error
(
&
error
,
TUMBLER_ERROR
,
TUMBLER_ERROR_INVALID_FORMAT
,
TUMBLER_ERROR_MESSAGE_CREATION_FAILED
);
g_signal_emit_by_name
(
thumbnailer
,
"error"
,
uri
,
error
->
domain
,
error
->
code
,
error
->
message
);
g_error_free
(
error
);
return
;
}
/* get size of dest thumb */
thumbnail
=
tumbler_file_info_get_thumbnail
(
info
);
flavor
=
tumbler_thumbnail_get_flavor
(
thumbnail
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment