0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-27 11:18:51 +02:00

modules/media: Fix missing url decoding of mxc path params.

This commit is contained in:
Jason Volk 2023-02-22 13:14:46 -08:00
parent 314dacdce0
commit 73f4a68b8f
3 changed files with 16 additions and 18 deletions

View file

@ -175,11 +175,12 @@ ircd::m::media::file::download(const mutable_buffer &buf_,
fed::request::opts fedopts;
fedopts.remote = remote?: mxc.server;
json::get<"method"_>(fedopts.request) = "GET";
thread_local char mxc_buf[2][2048];
json::get<"uri"_>(fedopts.request) = fmt::sprintf
{
buf, "/_matrix/media/r0/download/%s/%s",
mxc.server,
mxc.mediaid,
url::encode(mxc_buf[0], mxc.server),
url::encode(mxc_buf[1], mxc.mediaid),
};
consume(buf, size(json::get<"uri"_>(fedopts.request)));

View file

@ -25,8 +25,7 @@ download_resource
static m::resource::response
get__download_local(client &client,
const m::resource::request &request,
const string_view &server,
const string_view &file,
const m::media::mxc &mxc,
const m::room &room);
static m::resource::response
@ -39,14 +38,11 @@ get__download(client &client,
http::MULTIPLE_CHOICES, "/ download / domain / file"
};
const auto &server
char url_buf[2][256];
const m::media::mxc mxc
{
request.parv[0]
};
const auto &file
{
request.parv[1]
url::decode(url_buf[0], request.parv[0]),
url::decode(url_buf[1], request.parv[1]),
};
// Download doesn't require auth so if there is no user_id detected
@ -65,17 +61,16 @@ get__download(client &client,
const m::room::id::buf room_id
{
m::media::file::download({server, file}, user_id)
m::media::file::download(mxc, user_id)
};
return get__download_local(client, request, server, file, room_id);
return get__download_local(client, request, mxc, room_id);
}
static m::resource::response
get__download_local(client &client,
const m::resource::request &request,
const string_view &server,
const string_view &file,
const m::media::mxc &mxc,
const m::room &room)
{
static const m::event::fetch::opts fopts
@ -145,8 +140,8 @@ get__download_local(client &client,
log::error
{
m::media::log, "File %s/%s [%s] size mismatch: expected %zu got %zu",
server,
file,
mxc.server,
mxc.mediaid,
string_view{room.room_id},
file_size,
read

View file

@ -108,9 +108,11 @@ get__thumbnail(client &client,
"Media ID parameter required"
};
char url_buf[2][256];
const m::media::mxc mxc
{
request.parv[0], request.parv[1]
url::decode(url_buf[0], request.parv[0]),
url::decode(url_buf[1], request.parv[1]),
};
// Thumbnail doesn't require auth so if there is no user_id detected