fix: check texture size for capes

This commit is contained in:
Pig Fang 2021-05-04 18:20:24 +08:00
parent 6226784b10
commit b7af1ebf19
No known key found for this signature in database
GPG Key ID: A8198F548DADA9E2
2 changed files with 25 additions and 10 deletions

View File

@ -219,6 +219,17 @@ class SkinlibController extends Controller
$type = $data['type'];
$size = getimagesize($file);
if ($size[0] % 64 != 0 || $size[1] % 32 != 0) {
$message = trans('skinlib.upload.invalid-size', [
'type' => $type === 'cape' ? trans('general.cape') : trans('general.skin'),
'width' => $size[0],
'height' => $size[1],
]);
return json($message, 1);
}
$ratio = $size[0] / $size[1];
if ($type == 'steve' || $type == 'alex') {
if ($ratio != 2 && $ratio != 1 || $type === 'alex' && $ratio === 2) {
@ -228,15 +239,6 @@ class SkinlibController extends Controller
'height' => $size[1],
]);
return json($message, 1);
}
if ($size[0] % 64 != 0 || $size[1] % 32 != 0) {
$message = trans('skinlib.upload.invalid-hd-skin', [
'type' => trans('general.skin'),
'width' => $size[0],
'height' => $size[1],
]);
return json($message, 1);
}
} elseif ($type == 'cape') {

View File

@ -337,12 +337,25 @@ class SkinlibControllerTest extends TestCase
'file' => UploadedFile::fake()->image('texture.png', 100, 50),
])->assertJson([
'code' => 1,
'message' => trans('skinlib.upload.invalid-hd-skin', [
'message' => trans('skinlib.upload.invalid-size', [
'type' => trans('general.skin'),
'width' => 100,
'height' => 50,
]),
]);
$this->postJson(route('texture.upload'), [
'name' => 'texture',
'public' => true,
'type' => 'cape',
'file' => UploadedFile::fake()->image('texture.png', 100, 50),
])->assertJson([
'code' => 1,
'message' => trans('skinlib.upload.invalid-size', [
'type' => trans('general.cape'),
'width' => 100,
'height' => 50,
]),
]);
$this->postJson(route('texture.upload'), [
'name' => 'texture',
'public' => true,