Pepelac
Well-known member
Hi.
After receiving some reports from users, that they can't upload avatars because of error "Your avatar's file size is too large. Please upload an avatar no bigger than XX KB", I've tried to dig into the code.
It's a very strange idea to check user group avatar limits after uploading and resizing the source image. I'm talking about XenForo_Model_Avatar::applyAvatar() method. There is a condition at the line #146:
This piece of code checks size of the resampled image. And there is the problem - size of the resampled image can be larger, than the size of the uploaded image.
Here is an example. Let's say, that I have a PNG image about 6 KB. And avatar size limited to 9.8 KB. After uploading, the size of the resampled image is 34 KB. And now user sees the error message and the only thought that we can read in his eyes is "WTF!!! I've just uploaded the image of size 6 KB! "...
And here are variables from the debug process:
After receiving some reports from users, that they can't upload avatars because of error "Your avatar's file size is too large. Please upload an avatar no bigger than XX KB", I've tried to dig into the code.
It's a very strange idea to check user group avatar limits after uploading and resizing the source image. I'm talking about XenForo_Model_Avatar::applyAvatar() method. There is a condition at the line #146:
PHP:
if ($maxFileSize != -1 && filesize($outputFiles[$sizeCode]) > $maxFileSize)
This piece of code checks size of the resampled image. And there is the problem - size of the resampled image can be larger, than the size of the uploaded image.
Here is an example. Let's say, that I have a PNG image about 6 KB. And avatar size limited to 9.8 KB. After uploading, the size of the resampled image is 34 KB. And now user sees the error message and the only thought that we can read in his eyes is "WTF!!! I've just uploaded the image of size 6 KB! "...
And here are variables from the debug process: