Skip to content

fix: increase byte array length limit for 1.7.x clients in WriteBytes17#558

Merged
robinbraemer merged 1 commit into
masterfrom
fix/1.7.x-login-byte-array-length
Sep 4, 2025
Merged

fix: increase byte array length limit for 1.7.x clients in WriteBytes17#558
robinbraemer merged 1 commit into
masterfrom
fix/1.7.x-login-byte-array-length

Conversation

@robinbraemer

Copy link
Copy Markdown
Member

Problem

Issue #533 reported that 1.7.x clients fail to login with the error:
Cannot write byte array longer than 127 (got 162 bytes)

This affects basic connectivity for 1.7.x Minecraft clients, preventing them from logging into the proxy.

Fixes #533

Root Cause

The WriteBytes17() function in pkg/edition/java/proto/util/writer.go was checking byte array length against math.MaxInt8 (127) when allowExtended=false, but this limit is too restrictive for 1.7.x encryption requests.

RSA public keys used in encryption requests are typically ~162 bytes in DER format, which exceeds the 127-byte limit.

Solution

Updated WriteBytes17() to use math.MaxInt16 (32767) instead of math.MaxInt8 (127) for non-extended mode, matching Velocity's behavior.

Reference: Velocity's ProtocolUtils.writeByteArray17() uses Short.MAX_VALUE (32767) when allowExtended=false.

Changes

  • writer.go: Changed limit from math.MaxInt8 to math.MaxInt16
  • writer_test.go: Added comprehensive tests including:

Testing

✅ All new tests pass
✅ Existing proto package tests pass
✅ Project builds successfully
✅ Specific test case for 162-byte array (from #533) now works

Verification

The fix specifically addresses the case where:

  1. 1.7.x client attempts to login
  2. Gate sends EncryptionRequest packet with RSA public key (~162 bytes)
  3. WriteBytes17(publicKey, false) is called
  4. Previously failed at 127-byte limit, now succeeds with 32767-byte limit

This change maintains backward compatibility while fixing 1.7.x client login issues.

Issue #533 reported that 1.7.x clients fail to login with error:
'Cannot write byte array longer than 127 (got 162 bytes)'

The problem was in WriteBytes17() function which was checking against
math.MaxInt8 (127) for non-extended mode, but should check against
math.MaxInt16 (32767) to match Velocity's behavior.

This change:
- Updates WriteBytes17 to use math.MaxInt16 limit for allowExtended=false
- Matches Velocity's ProtocolUtils.writeByteArray17 implementation
- Fixes 1.7.x login failures caused by RSA public key size (~162 bytes)
- Adds comprehensive tests including the specific 162-byte case from #533

Fixes #533
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying gate-minekube with  Cloudflare Pages  Cloudflare Pages

Latest commit: fefc1f5
Status: ✅  Deploy successful!
Preview URL: https://ce22e658.gate-minekube.pages.dev
Branch Preview URL: https://fix-1-7-x-login-byte-array-l.gate-minekube.pages.dev

View logs

@robinbraemer robinbraemer merged commit 0dc2f12 into master Sep 4, 2025
13 checks passed
@robinbraemer robinbraemer deleted the fix/1.7.x-login-byte-array-length branch September 4, 2025 12:57
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

Successfully merging this pull request may close these issues.

bug: 1.7.x login fails due to byte array length

1 participant