3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 00:00:41 +01:00

Separate method for Base64 length calc. Added offset method in RawSkin

Dieser Commit ist enthalten in:
Tim203 2020-12-19 22:45:34 +01:00
Ursprung e69ad0e560
Commit 2f1acb1e6f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 064EE9F5BF7C3EE8
2 geänderte Dateien mit 43 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,35 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.floodgate.util;
public class Base64Utils {
public static int getEncodedLength(int length) {
if (length <= 0) {
return -1;
}
return 4 * ((length + 2) / 3);
}
}

Datei anzeigen

@ -45,13 +45,18 @@ public final class RawSkin {
} }
public static RawSkin decode(byte[] data) throws InvalidFormatException { public static RawSkin decode(byte[] data) throws InvalidFormatException {
return decode(data, 0);
}
public static RawSkin decode(byte[] data, int offset) throws InvalidFormatException {
// offset is an amount of bytes before the Base64 starts
if (data == null) { if (data == null) {
return null; return null;
} }
int maxEncodedLength = 4 * (((64 * 64 * 4 + 9) + 2) / 3); int maxEncodedLength = Base64Utils.getEncodedLength(64 * 64 * 4 + 9);
// if the RawSkin is longer then the max Java Edition skin length // if the RawSkin is longer then the max Java Edition skin length
if (data.length > maxEncodedLength) { if ((data.length - offset) > maxEncodedLength) {
throw new InvalidFormatException(format( throw new InvalidFormatException(format(
"Encoded data cannot be longer then %s bytes! Got %s", "Encoded data cannot be longer then %s bytes! Got %s",
maxEncodedLength, data.length maxEncodedLength, data.length
@ -59,7 +64,7 @@ public final class RawSkin {
} }
// if the encoded data doesn't even contain the width, height (8 bytes, 2 ints) and isAlex // if the encoded data doesn't even contain the width, height (8 bytes, 2 ints) and isAlex
if (data.length < 4 * ((9 + 2) / 3)) { if ((data.length - offset) < Base64Utils.getEncodedLength(9)) {
throw new InvalidFormatException("Encoded data must be at least 16 bytes long!"); throw new InvalidFormatException("Encoded data must be at least 16 bytes long!");
} }