mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-29 06:03:33 -04:00
add length check
This commit is contained in:
parent
b2b8ad2372
commit
043330a8e6
@ -10,8 +10,11 @@ module.exports = {
|
|||||||
'restBuffer': [readRestBuffer, writeRestBuffer, sizeOfRestBuffer],
|
'restBuffer': [readRestBuffer, writeRestBuffer, sizeOfRestBuffer],
|
||||||
'entityMetadataLoop': [readEntityMetadata, writeEntityMetadata, sizeOfEntityMetadata]
|
'entityMetadataLoop': [readEntityMetadata, writeEntityMetadata, sizeOfEntityMetadata]
|
||||||
};
|
};
|
||||||
|
var PartialReadError=require('protodef').utils.PartialReadError;
|
||||||
|
|
||||||
function readUUID(buffer, offset) {
|
function readUUID(buffer, offset) {
|
||||||
|
if(offset+16>buffer.length)
|
||||||
|
throw new PartialReadError();
|
||||||
return {
|
return {
|
||||||
value: UUID.stringify(buffer.slice(offset,16+offset)),
|
value: UUID.stringify(buffer.slice(offset,16+offset)),
|
||||||
size: 16
|
size: 16
|
||||||
@ -38,6 +41,8 @@ function sizeOfNbt(value) {
|
|||||||
|
|
||||||
|
|
||||||
function readOptionalNbt(buffer, offset) {
|
function readOptionalNbt(buffer, offset) {
|
||||||
|
if(offset+1>buffer.length)
|
||||||
|
throw new PartialReadError();
|
||||||
if(buffer.readInt8(offset) == 0) return {size:1};
|
if(buffer.readInt8(offset) == 0) return {size:1};
|
||||||
return nbt.proto.read(buffer,offset,"nbt");
|
return nbt.proto.read(buffer,offset,"nbt");
|
||||||
}
|
}
|
||||||
@ -58,8 +63,12 @@ function sizeOfOptionalNbt(value) {
|
|||||||
|
|
||||||
// Length-prefixed compressed NBT, see differences: http://wiki.vg/index.php?title=Slot_Data&diff=6056&oldid=4753
|
// Length-prefixed compressed NBT, see differences: http://wiki.vg/index.php?title=Slot_Data&diff=6056&oldid=4753
|
||||||
function readCompressedNbt(buffer, offset) {
|
function readCompressedNbt(buffer, offset) {
|
||||||
|
if(offset+2>buffer.length)
|
||||||
|
throw new PartialReadError();
|
||||||
const length = buffer.readInt16BE(offset);
|
const length = buffer.readInt16BE(offset);
|
||||||
if(length == -1) return {size:2};
|
if(length == -1) return {size:2};
|
||||||
|
if(offset+2+length>buffer.length)
|
||||||
|
throw new PartialReadError();
|
||||||
|
|
||||||
const compressedNbt = buffer.slice(offset+2, offset+2+length);
|
const compressedNbt = buffer.slice(offset+2, offset+2+length);
|
||||||
|
|
||||||
@ -119,6 +128,8 @@ function readEntityMetadata(buffer, offset, {type,endVal}) {
|
|||||||
const metadata = [];
|
const metadata = [];
|
||||||
let item;
|
let item;
|
||||||
while(true) {
|
while(true) {
|
||||||
|
if(offset+1>buffer.length)
|
||||||
|
throw new PartialReadError();
|
||||||
item = buffer.readUInt8(cursor);
|
item = buffer.readUInt8(cursor);
|
||||||
if(item === endVal) {
|
if(item === endVal) {
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user