Limit number of book pages in 1.17->1.17.1

This commit is contained in:
KennyTV 2021-06-29 19:19:02 +02:00
parent 77a5b2212b
commit a654becac8
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
3 changed files with 13 additions and 3 deletions

View File

@ -5,7 +5,7 @@ plugins {
allprojects {
group = "com.viaversion"
version = "4.0.1-1.17.1-pre1-SNAPSHOT"
version = "4.0.1-1.17.1-pre2-SNAPSHOT"
description = "Allow older clients to join newer server versions."
}

View File

@ -34,6 +34,7 @@ public final class Protocol1_17To1_17_1 extends BackwardsProtocol<ClientboundPac
private static final int MAX_PAGE_LENGTH = 8192;
private static final int MAX_TITLE_LENGTH = 128;
private static final int MAX_PAGES = 200; // Actually limited to 100 when handling the read packet, but /shrug
public Protocol1_17To1_17_1() {
super(ClientboundPackets1_17.class, ClientboundPackets1_17.class, ServerboundPackets1_17.class, ServerboundPackets1_17.class);
@ -108,6 +109,7 @@ public final class Protocol1_17To1_17_1 extends BackwardsProtocol<ClientboundPac
CompoundTag tag = item.tag();
ListTag pagesTag;
StringTag titleTag = null;
// Sanity checks
if (tag == null || (pagesTag = tag.get("pages")) == null
|| (signing && (titleTag = tag.get("title")) == null)) {
wrapper.write(Type.VAR_INT, 0); // Pages length
@ -115,13 +117,19 @@ public final class Protocol1_17To1_17_1 extends BackwardsProtocol<ClientboundPac
return;
}
// Write pages
// Write pages - limit them first
if (pagesTag.size() > MAX_PAGES) {
pagesTag = new ListTag(pagesTag.getValue().subList(0, MAX_PAGES));
}
wrapper.write(Type.VAR_INT, pagesTag.size());
for (Tag pageTag : pagesTag) {
String page = ((StringTag) pageTag).getValue();
// Limit page length
if (page.length() > MAX_PAGE_LENGTH) {
page = page.substring(0, MAX_PAGE_LENGTH);
}
wrapper.write(Type.STRING, page);
}
@ -132,10 +140,12 @@ public final class Protocol1_17To1_17_1 extends BackwardsProtocol<ClientboundPac
titleTag = tag.get("title");
}
// Limit title length
String title = titleTag.getValue();
if (title.length() > MAX_TITLE_LENGTH) {
title = title.substring(0, MAX_TITLE_LENGTH);
}
wrapper.write(Type.STRING, title);
}
});

View File

@ -3,7 +3,7 @@ metadata.format.version = "1.0"
[versions]
# ViaVersion
viaver = "4.0.1-1.17.1-pre1-SNAPSHOT"
viaver = "4.0.1-1.17.1-pre2-SNAPSHOT"
# Common provided
netty = "4.0.20.Final"