fix: Don't trust the info block of events

This commit is contained in:
Sorunome 2020-09-10 11:10:38 +02:00
parent 5d45c224a3
commit e08f35b5d0
No known key found for this signature in database
GPG key ID: B19471D07FC9BE9C

View file

@ -406,7 +406,7 @@ class Event extends MatrixEvent {
// Is this file storeable? // Is this file storeable?
final infoMap = final infoMap =
getThumbnail ? content['info']['thumbnail_info'] : content['info']; getThumbnail ? content['info']['thumbnail_info'] : content['info'];
final storeable = room.client.database != null && var storeable = room.client.database != null &&
infoMap is Map<String, dynamic> && infoMap is Map<String, dynamic> &&
infoMap['size'] is int && infoMap['size'] is int &&
infoMap['size'] <= room.client.database.maxFileSize; infoMap['size'] <= room.client.database.maxFileSize;
@ -422,6 +422,8 @@ class Event extends MatrixEvent {
}; };
uint8list = uint8list =
await downloadCallback(mxContent.getDownloadLink(room.client)); await downloadCallback(mxContent.getDownloadLink(room.client));
storeable = storeable &&
uint8list.lengthInBytes < room.client.database.maxFileSize;
if (storeable) { if (storeable) {
await room.client.database await room.client.database
.storeFile(mxContent.toString(), uint8list, DateTime.now()); .storeFile(mxContent.toString(), uint8list, DateTime.now());