Pumpkin-MC/Pumpkin · error

expected i32

Error message

expected i32

What it means

Thrown by `PacketReadSlice for i32` when fewer than 4 bytes remain in the buffer. Decoding a little-endian i32 requires exactly 4 bytes. This UnexpectedEof error signals a truncated payload or field misalignment.

Solutions

  1. Verify at least 4 bytes remain before decoding the field
  2. Re-check earlier VarUInt reads for byte-count correctness
  3. Validate payload length against the packet header
  4. Reject the malformed packet and log the offset

Example fix

// before
let pos_x = i32::read_slice(&mut buf)?;
// after
if buf.len() < 4 { return Err(PacketError::Truncated); }
let pos_x = i32::read_slice(&mut buf)?;
Defensive patterns

Strategy: try-catch

Validate before calling

if buf.len() < 4 { return Err(PacketError::Truncated); }

Try / catch

let x = i32::read_slice(&mut buf)
    .map_err(|_| PacketError::Truncated)?;

Prevention

When it happens

Trigger: i32::read_slice called when buf.len() < 4 — the remaining bytes cannot supply a full 32-bit integer.

Common situations: Truncated packet; misalignment caused by an earlier variable-length field (VarUInt) parsing fewer/more bytes than expected; wrong protocol field order.

Related errors


AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09). Data as JSON: /api/errors/6230b30d4738cb8d. Report an issue: GitHub.

Appendix: source

Thrown at crates/pumpkin-protocol/src/serial/deserializer.rs:311

impl<'a> PacketReadSlice<'a> for i16 {
    fn read_slice(buf: &mut &'a [u8]) -> Result<Self, Error> {
        if buf.len() < 2 {
            return Err(Error::new(ErrorKind::UnexpectedEof, "expected i16"));
        }
        let (bytes, rest) = buf.split_at(2);
        *buf = rest;
        let arr = bytes
            .try_into()
            .map_err(|_| Error::new(ErrorKind::InvalidData, "invalid i16 slice"))?;
        Ok(Self::from_le_bytes(arr))
    }
}

impl<'a> PacketReadSlice<'a> for i32 {
    fn read_slice(buf: &mut &'a [u8]) -> Result<Self, Error> {
        if buf.len() < 4 {
            return Err(Error::new(ErrorKind::UnexpectedEof, "expected i32"));
        }
        let (bytes, rest) = buf.split_at(4);
        *buf = rest;
        let arr = bytes
            .try_into()
            .map_err(|_| Error::new(ErrorKind::InvalidData, "invalid i32 slice"))?;
        Ok(Self::from_le_bytes(arr))
    }
}

impl<'a> PacketReadSlice<'a> for i64 {
    fn read_slice(buf: &mut &'a [u8]) -> Result<Self, Error> {
        if buf.len() < 8 {
            return Err(Error::new(ErrorKind::UnexpectedEof, "expected i64"));
        }
        let (bytes, rest) = buf.split_at(8);
        *buf = rest;
        let arr = bytes

View on GitHub (pinned to 8d4639e25a)