Scissors/patches/server/0042-Validate-block-entity-...

34 lines
2.3 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Luna <lunahatesgogle@gmail.com>
Date: Mon, 11 Jul 2022 17:10:17 -0300
Subject: [PATCH] Validate block entity tag query positions
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index a102586b42ac408a3f655f7c0d069ab0990ec7fc..1c56ca1f7ed3064bfd3352cf46741fc64bbee4eb 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1240,7 +1240,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
if (this.player.hasPermissions(2)) {
Entity entity = this.player.getLevel().getEntity(packet.getEntityId());
- if (entity != null) {
+ if (entity != null && !isOutsideOfReach(entity.position().x, entity.position().y, entity.position().z)) { // Scissors - Prevent querying of entities out of reach
CompoundTag nbttagcompound = entity.saveWithoutId(new CompoundTag());
this.player.connection.send(new ClientboundTagQueryPacket(packet.getTransactionId(), nbttagcompound));
@@ -1252,8 +1252,11 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@Override
public void handleBlockEntityTagQuery(ServerboundBlockEntityTagQuery packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
- if (this.player.hasPermissions(2)) {
- BlockEntity tileentity = this.player.getLevel().getBlockEntity(packet.getPos());
+ // Scissors start - Validate block entity tag query positions, prevent querying block entities out of reach
+ final BlockPos pos = packet.getPos();
+ if (this.player.hasPermissions(2) && Level.isInSpawnableBounds(pos) && !isOutsideOfReach(pos.getX(), pos.getY(), pos.getZ())) {
+ BlockEntity tileentity = this.player.getLevel().isLoaded(pos) ? this.player.getLevel().getBlockEntity(pos) : null;
+ // Scissors end
CompoundTag nbttagcompound = tileentity != null ? tileentity.save(new CompoundTag()) : null;
this.player.connection.send(new ClientboundTagQueryPacket(packet.getTransactionId(), nbttagcompound));