Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash crafting using proxy on bedrock servers #515

Open
bentonjj opened this issue Jul 31, 2024 · 15 comments
Open

Crash crafting using proxy on bedrock servers #515

bentonjj opened this issue Jul 31, 2024 · 15 comments

Comments

@bentonjj
Copy link

bentonjj commented Jul 31, 2024

Get the below crash crafting anything on Bedrock servers when connected with proxy. Tried 1.20.80 and 1.21.2 clients, even when using basic proxy script example code:

C:\bedrock\node_modules\protodef\src\compiler.js:114
throw e
^

Error: Read error for undefined : array size is abnormally large, not reading: 16777216
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :342:37)
at Object.ItemExtraDataWithoutBlockingTick (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :351:9)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :386:47)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :388:17)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :390:13)
at Object.ItemLegacy (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :392:9)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :1577:48)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :1582:17)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :1585:13)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :1587:11)

Node.js v18.20.4

@extremeheat
Copy link
Member

Can you reproduce this on another server or a vanilla server?

@bentonjj
Copy link
Author

bentonjj commented Jul 31, 2024 via email

@bentonjj bentonjj changed the title Crash crafting on LifeBoat survival servers Crash crafting using proxy on bedrock servers Jul 31, 2024
@bentonjj
Copy link
Author

bentonjj commented Aug 3, 2024

The work around is to downgrade minecraft-data package to 3.66.0. Go to https://github.com/PrismarineJS/minecraft-data/releases and download the minecraft-data-3.66.0.zip file. Extract to node_modules\minecraft-data\minecraft-data. You will be limited to the 1.21.0 client and older as newer clients require minecraft-data 3.67.0 which causes the issue in all client versions.

@extremeheat
Copy link
Member

Can you please set Error.stackTraceLimit = Infinity at the top of your program and post the stack trace again?

@bentonjj
Copy link
Author

bentonjj commented Aug 3, 2024

This is the code:

Error.stackTraceLimit = Infinity
const { Relay } = require('bedrock-protocol')
const relay = new Relay({version: '1.20.80', host: '10.10.0.10', port: 4000, destination: { host: '10.10.0.10', port: 3000 }})
relay.listen()
relay.on('connect', player => {
console.log('New connection', player.connection.address)
player.on('serverbound', ({ name, params }) => {
})
})

Client is version 1.20.81 and server from minecraft.net is version 1.20.81.01

This is the output after the crash adding any item to inventory:

New connection 10.10.0.10/55385
C:\bedrock\node_modules\protodef\src\compiler.js:114
throw e
^

Error: Read error for undefined : array size is abnormally large, not reading: 16777216
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :342:37)
at Object.ItemExtraDataWithoutBlockingTick (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :351:9)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :386:47)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :388:17)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :390:13)
at Object.ItemLegacy (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :392:9)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :1577:48)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :1582:17)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :1585:13)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :1587:11)
at Object.ItemStackRequest (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :1592:9)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :4267:46)
at Object.packet_item_stack_request (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :4272:9)
at eval (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :2029:76)
at mcpe_packet (eval at compile (C:\bedrock\node_modules\protodef\src\compiler.js:258:12), :2092:9)
at CompiledProtodef.read (C:\bedrock\node_modules\protodef\src\compiler.js:70:12)
at e.message (C:\bedrock\node_modules\protodef\src\compiler.js:111:49)
at tryCatch (C:\bedrock\node_modules\protodef\src\utils.js:50:16)
at CompiledProtodef.parsePacketBuffer (C:\bedrock\node_modules\protodef\src\compiler.js:111:29)
at Parser.parsePacketBuffer (C:\bedrock\node_modules\protodef\src\serializer.js:68:23)
at RelayPlayer.readPacket (C:\bedrock\node_modules\bedrock-protocol\src\relay.js:133:44)
at RelayPlayer.onDecryptedPacket (C:\bedrock\node_modules\bedrock-protocol\src\connection.js:163:12)
at Decipheriv.verify (C:\bedrock\node_modules\bedrock-protocol\src\transforms\encryption.js:92:12)
at Decipheriv.emit (node:events:519:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5)
at Decipheriv._transform (node:internal/crypto/cipher:159:8)
at Transform._write (node:internal/streams/transform:171:8)
at writeOrBuffer (node:internal/streams/writable:570:12)
at _write (node:internal/streams/writable:499:10)
at Writable.write (node:internal/streams/writable:508:10)
at RelayPlayer.decrypt (C:\bedrock\node_modules\bedrock-protocol\src\transforms\encryption.js:98:21)
at RelayPlayer.handle (C:\bedrock\node_modules\bedrock-protocol\src\connection.js:170:14)
at C:\bedrock\node_modules\bedrock-protocol\src\server.js:105:35
at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

Node.js v20.16.0

@extremeheat
Copy link
Member

extremeheat commented Aug 3, 2024

OK, please add some logging like this:

const fs = require('fs')

relay.on('connect', (player) => {

  const file = fs.createWriteStream('log.txt')
  player.downInLog = function (...e) {
    file.write(JSON.stringify(e) + '\n')
  }

})

and provide the log.txt file (either here or or http://gist.github.com). That should contain needed packet buffer information.

@bentonjj
Copy link
Author

bentonjj commented Aug 4, 2024

Sorry program simply exits when I connect and does not create any log file. This is what I'm using:

Error.stackTraceLimit = Infinity
const { Relay } = require('bedrock-protocol')
const relay = new Relay({version: '1.20.80', host: '10.10.0.10', port: 4000, destination: { host: '10.10.0.10', port: 3000 }})
relay.listen()
relay.on('connect', player => {
const file = fs.createWriteStream('log.txt')
player.downInLog = function (...e) {file.write(JSON.stringify(e) + '\n')}
console.log('New connection', player.connection.address)
player.on('serverbound', ({ name, params }) => {
})
})

@bentonjj
Copy link
Author

bentonjj commented Aug 4, 2024

This is the log:

log.txt

This is the code I'm using:

BigInt.prototype.toJSON = function() { return this.toString() }
const { Relay } = require('bedrock-protocol')
const relay = new Relay({version: '1.20.80', host: '10.10.0.10', port: 4000, destination: { host: '10.10.0.10', port: 3000 }})
relay.listen()
const fs = require('fs')

relay.on('connect', (player) => {

const file = fs.createWriteStream('log.txt')
player.downInLog = function (...e) {
file.write(JSON.stringify(e) + '\n')
}
})

I had to add the first line to resolve a "TypeError: Do not know how to serialize a BigInt"

@bentonjj
Copy link
Author

bentonjj commented Aug 4, 2024

You can pick up items, take items from chests, and use /give command with no crash. Crash happens when crafting an item on crafting table or adding item to inventory from creative mode.

@extremeheat
Copy link
Member

Looking into the crafting issue, seems a bit odd that the buffer is using craft_creative as opposed to auto which was updated.

I can separately confirm the issue with the movement correction packet, that is missing a field since 1.20.80.

@extremeheat
Copy link
Member

Ah wow, crafting issue seems to be caused by a bug in protodef compiler's codegen. Anonymous containers with switches have bad code generation.

@extremeheat
Copy link
Member

Will be fixed by ProtoDef-io/node-protodef#159

@extremeheat
Copy link
Member

Would be great if people could test out the above PR.

@extremeheat
Copy link
Member

extremeheat commented Aug 18, 2024

Movement correction issue fixed upstream with #522.

But again if anyone could test above PR in ProtoDef that would be great.

@bentonjj
Copy link
Author

bentonjj commented Oct 27, 2024

Exactly how to I apply the fix? A fresh install using "npm install bedrock-protocol" and using vanilla 1.20.81 client and server still crashes crafting or adding to inventory in creative mode. Update: running a "npm install protodef" updates the code with the fix (installing just bedrock-protocol puts an older version) and also had to run a "npm install minecraft-data" to add support for newer versions. Crafting seems to function normally on 1.21.30 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@extremeheat @bentonjj and others