Skip to content

Commit 8dea6f1

Browse files
committed
Fork friendly byte buf correctly
1 parent b4682bf commit 8dea6f1

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--- a/net/minecraft/nbt/NbtAccounter.java
2+
+++ b/net/minecraft/nbt/NbtAccounter.java
3+
@@ -48,6 +_,16 @@
4+
}
5+
}
6+
7+
+ // Paper start - Track codec depth
8+
+ public void pushDepth(final int depth) {
9+
+ if (this.depth + depth >= this.maxDepth) {
10+
+ throw new NbtAccounterException("Tried to read NBT tag with too high complexity, depth > " + this.maxDepth);
11+
+ } else {
12+
+ this.depth += depth;
13+
+ }
14+
+ }
15+
+ // Paper end - Track codec depth
16+
+
17+
public void pushDepth() {
18+
if (this.depth >= this.maxDepth) {
19+
throw new NbtAccounterException("Tried to read NBT tag with too high complexity, depth > " + this.maxDepth);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--- a/net/minecraft/network/RegistryFriendlyByteBuf.java
2+
+++ b/net/minecraft/network/RegistryFriendlyByteBuf.java
3+
@@ -12,6 +_,15 @@
4+
this.registryAccess = registryAccess;
5+
}
6+
7+
+ // Paper start - Track codec depth
8+
+ public RegistryFriendlyByteBuf(final ByteBuf source, final RegistryFriendlyByteBuf parent) {
9+
+ super(source);
10+
+ this.registryAccess = parent.registryAccess;
11+
+ this.trackCodecDepth = parent.trackCodecDepth;
12+
+ this.codecDepth = parent.codecDepth;
13+
+ }
14+
+ // Paper end - Track codec depth
15+
+
16+
public RegistryAccess registryAccess() {
17+
return this.registryAccess;
18+
}

paper-server/patches/sources/net/minecraft/network/codec/ByteBufCodecs.java.patch

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
--- a/net/minecraft/network/codec/ByteBufCodecs.java
22
+++ b/net/minecraft/network/codec/ByteBufCodecs.java
3+
@@ -334,7 +_,13 @@
4+
return new StreamCodec<ByteBuf, Tag>() {
5+
@Override
6+
public Tag decode(final ByteBuf input) {
7+
- Tag result = FriendlyByteBuf.readNbt(input, accounter.get());
8+
+ // Paper start - Track codec depth
9+
+ final NbtAccounter acc = accounter.get();
10+
+ if (input instanceof FriendlyByteBuf friendlyByteBuf && friendlyByteBuf.trackCodecDepth) {
11+
+ acc.pushDepth(friendlyByteBuf.codecDepth * 3);
12+
+ }
13+
+ Tag result = FriendlyByteBuf.readNbt(input, acc);
14+
+ // Paper end - Track codec depth
15+
if (result == null) {
16+
throw new DecoderException("Expected non-null compound tag");
17+
} else {
318
@@ -418,6 +_,48 @@
419
};
520
}
@@ -49,3 +64,12 @@
4964
static <B extends ByteBuf, V> StreamCodec<B, Optional<V>> optional(final StreamCodec<? super B, V> original) {
5065
return new StreamCodec<B, Optional<V>>() {
5166
@Override
67+
@@ -594,7 +_,7 @@
68+
}
69+
70+
static <V> StreamCodec.CodecOperation<RegistryFriendlyByteBuf, V, V> registryFriendlyLengthPrefixed(final int maxSize) {
71+
- return lengthPrefixed(maxSize, (parent, child) -> new RegistryFriendlyByteBuf(child, parent.registryAccess()));
72+
+ return lengthPrefixed(maxSize, (parent, child) -> new RegistryFriendlyByteBuf(child, parent)); // Paper - Track codec depth
73+
}
74+
75+
static <T> StreamCodec<ByteBuf, T> idMapper(final IntFunction<T> byId, final ToIntFunction<T> toId) {

0 commit comments

Comments
 (0)