mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 17:01:56 +01:00
Apply NBTReadLimiter to more things.
By: md_5 <git@md-5.net>
This commit is contained in:
parent
f972379105
commit
5b20d95920
2 changed files with 52 additions and 0 deletions
|
@ -5,3 +5,16 @@
|
||||||
package net.minecraft.nbt;
|
package net.minecraft.nbt;
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
|
@@ -324,6 +325,12 @@
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompoundTag read(DataInput input, NbtAccounter tracker) throws IOException {
|
||||||
|
+ // Spigot start
|
||||||
|
+ if ( input instanceof io.netty.buffer.ByteBufInputStream )
|
||||||
|
+ {
|
||||||
|
+ input = new DataInputStream(new org.spigotmc.LimitStream((InputStream) input, tracker));
|
||||||
|
+ }
|
||||||
|
+ // Spigot end
|
||||||
|
Tag nbtbase = NbtIo.readUnnamedTag(input, tracker);
|
||||||
|
|
||||||
|
if (nbtbase instanceof CompoundTag) {
|
||||||
|
|
39
paper-server/src/main/java/org/spigotmc/LimitStream.java
Normal file
39
paper-server/src/main/java/org/spigotmc/LimitStream.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package org.spigotmc;
|
||||||
|
|
||||||
|
import java.io.FilterInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import net.minecraft.nbt.NbtAccounter;
|
||||||
|
|
||||||
|
public class LimitStream extends FilterInputStream
|
||||||
|
{
|
||||||
|
|
||||||
|
private final NbtAccounter limit;
|
||||||
|
|
||||||
|
public LimitStream(InputStream is, NbtAccounter limit)
|
||||||
|
{
|
||||||
|
super( is );
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read() throws IOException
|
||||||
|
{
|
||||||
|
this.limit.accountBytes( 1 );
|
||||||
|
return super.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read(byte[] b) throws IOException
|
||||||
|
{
|
||||||
|
this.limit.accountBytes( b.length );
|
||||||
|
return super.read( b );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read(byte[] b, int off, int len) throws IOException
|
||||||
|
{
|
||||||
|
this.limit.accountBytes( len );
|
||||||
|
return super.read( b, off, len );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue