Skip to content

Commit 142e67c

Browse files
authored
feat: Added file size limit to avatars and banners (#1209)
1 parent 4427d09 commit 142e67c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

include/dpp/user.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
namespace dpp {
3030

31+
constexpr uint32_t MAX_AVATAR_SIZE = 10240 * 1000; // 10240KB.
32+
3133
/**
3234
* @brief Various bitmask flags used to represent information about a dpp::user
3335
*/

src/dpp/cluster/user.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,19 @@ void cluster::current_user_edit(const std::string &nickname, const std::string&
3838
};
3939

4040
if (!avatar_blob.empty()) {
41+
if(avatar_blob.size() > MAX_AVATAR_SIZE) { // Avatar limit is 10240 kb.
42+
throw dpp::length_exception(err_icon_size, "Avatar file exceeds discord limit of 10240 kilobytes");
43+
}
4144
j["avatar"] = "data:" + mimetypes.find(avatar_type)->second + ";base64," + base64_encode((unsigned char const*)avatar_blob.data(), static_cast<unsigned int>(avatar_blob.length()));
4245
}
4346

4447
if (!banner_blob.empty()) {
48+
/* There doesn't seem to be a banner limit (probably due to the limit of 640x280)
49+
* however, this is here as a precautionary.
50+
*/
51+
if(banner_blob.size() > MAX_AVATAR_SIZE) {
52+
throw dpp::length_exception(err_icon_size, "Banner file exceeds discord limit of 10240 kilobytes");
53+
}
4554
j["banner"] = "data:" + mimetypes.find(banner_type)->second + ";base64," + base64_encode((unsigned char const*)banner_blob.data(), static_cast<unsigned int>(banner_blob.length()));
4655
}
4756

0 commit comments

Comments
 (0)