Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Trirrin
Copy link
Contributor

@Trirrin Trirrin commented Jan 11, 2026

Summary

When SetReader is called (e.g., after enabling encryption), the new reader was not wrapped with fullReader. This caused incomplete reads for large packets because a single Read() call may return fewer bytes than requested.

Problem

The Decoder uses a fullReader wrapper to ensure complete reads via io.ReadFull:

func NewDecoder(r io.Reader, ...) *Decoder {
    return &Decoder{
        rd: &fullReader{r}, // using the fullReader is essential here!
        ...
    }
}

type fullReader struct{ io.Reader }
func (fr *fullReader) Read(p []byte) (int, error) { return io.ReadFull(fr.Reader, p) }

However, SetReader did not wrap the new reader:

func (d *Decoder) SetReader(rd io.Reader) {
    d.mu.Lock()
    d.rd = rd  // Missing fullReader wrapper!
    d.mu.Unlock()
}

When encryption is enabled, SetReader is called with a cipher.StreamReader, losing the fullReader protection. This causes large packets to be read incompletely, resulting in connection drops.

Fix

Wrap the reader with fullReader in SetReader():

func (d *Decoder) SetReader(rd io.Reader) {
    d.mu.Lock()
    d.rd = &fullReader{rd}
    d.mu.Unlock()
}

Testing

Tested with Syncmatica mod which sends large plugin messages (~100KB+) for schematic sharing. Before the fix, players were disconnected immediately after attempting to share schematics. After the fix, schematic sharing works correctly.

Related Issues

Likely related to #587 (large modpack disconnection issues)

When SetReader is called (e.g., after enabling encryption), the new reader
was not wrapped with fullReader. This caused incomplete reads for large
packets because a single Read() call may return fewer bytes than requested.

This fix wraps the reader with fullReader in SetReader(), ensuring that
io.ReadFull is used for all read operations, which guarantees complete
packet reads.

Fixes issues with mods like Syncmatica that send large plugin messages,
which would cause unexpected disconnections after encryption was enabled.

Related to minekube#587
Copy link
Member

@robinbraemer robinbraemer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@robinbraemer robinbraemer merged commit 4b5d548 into minekube:master Jan 11, 2026
4 checks passed
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.

2 participants