Commit graph

19 commits

Author SHA1 Message Date
Olivia Lee
f0f81db99b
return Option from media::data::search_file_metadata
This is useful to easily distinguish missing files from corrupted keys.
All existing usage sites have been modified so there is no behavior
change in this commit.
2024-12-01 16:18:04 -08:00
Olivia Lee
79bc2525e3
add unit tests for media key parsing
We've had at least a couple media key parsing bugs. Let's get a *little*
more confidence that this code works :)
2024-11-27 22:24:54 -08:00
Olivia Lee
103a4fb56b
handle media keys where thumbnail size contains 0xFF
Our current code should never write these, because we have an allowlist
of thumbnail sizes. None of the allowed sizes contain a 0xFF byte. We
have observed keys with a 0xFF in the thumbnail size a couple times on
real servers, and believe an early version of conduit wrote these before
the allowlist was added.

These keys were originally handled correctly, and were broken by
e2cba15ed2. Before that commit, we were
parsing media keys backwards, and never tried to read the thumbnail size
or mxc url.
2024-11-27 22:15:07 -08:00
Charles Hall
d388994657
rewrite media key parser
Fixes a regression in e2cba15ed2 where the
Content-Type and Content-Disposition parts are extracted in the wrong
order.

Fixes a long-standing issue in b6d721374f
where the Content-Type part was allowed to be completely missing rather
than present and 0 bytes long.

Improves the error messages for various parsing failures to be unique
and more obvious.
2024-09-19 15:27:10 -07:00
Charles Hall
cb3e0c620a
improve media key decoding logs
On my HS I observed 5 instances of keys with the following format:

* MXC bytes.
* A 0xFF byte.
* 4 bytes where the width and height are supposed to be, which are
  supposed to be 8 bytes in length.
* 3 consecutive 0xFF bytes. This means that the `content-type` and
  `content-disposition` sections both parse as the empty string, and
  there's an extra separator at the end too.
* Extra bytes, all of which were `image/png`.

The 4 bytes where the width and height are supposed to be were one of:

* 003ED000
* 003EE000
* 003EF001

Which seems to have some kind of pattern to it...

After much digging, we have absolutely no idea what could've caused
this. Cursed.
2024-09-19 15:23:20 -07:00
Benjamin Lee
9d14c5d461
add admin command to delete all remote media files 2024-09-17 19:31:51 -07:00
Benjamin Lee
d7087c66bb
add admin command to delete individual media files 2024-09-17 19:13:54 -07:00
Benjamin Lee
7672cc8473
use OwnedMxcUri in media service
Not using `MxcData` because it borrows it's fields, and so we wouldn't
be able to return an owned `MxcData` from functions that read the db.
2024-09-15 00:32:17 -07:00
Benjamin Lee
e2cba15ed2
factor out helper for parsing media keys
Leaving this private in `database::key_value::media` because the way
the metadata is encoded in media keys is a mess. I want to fix that in
the future, and want to limit the number of things that rely on it for
now.
2024-09-15 00:32:17 -07:00
Lambda
a4b7df1b3a media: use FileMeta instead of tuples 2024-09-01 09:42:45 +00:00
Lambda
1ccb1e572b media: add MediaFileKey wrapper
One more win in the fight against the Vec<u8>s
2024-09-01 09:42:45 +00:00
Charles Hall
0afc1d2f50
change rustfmt configuration
This change is fully automated, except the `rustfmt.toml` changes and
a few clippy directives to allow specific functions with too many lines
because they are longer now.
2024-05-16 19:11:40 -07:00
Timo Kösters
d5b4754cf4
0 errors left! 2022-10-10 14:02:02 +02:00
Timo Kösters
a4637e2ba1
cargo fmt 2022-10-10 14:02:01 +02:00
Timo Kösters
44fe6d1554
127 errors left 2022-10-10 14:02:00 +02:00
Timo Kösters
cff52d7ebb
messing around with arcs 2022-10-10 14:02:00 +02:00
Timo Kösters
face766e0f
messing with trait objects 2022-10-10 14:02:00 +02:00
Timo Kösters
bd8b616ca0
Fixed more compile time errors 2022-10-10 13:54:00 +02:00
Nyaaori
232978087a
refactor: prepare database/key_value/media.rs from service/media.rs 2022-10-10 13:52:07 +02:00
Renamed from src/service/media.rs (Browse further)