Skip to content

Index-Out-Of-Bounds panic when using #[serde(skip_serializing_if = "Option::is_none")] #226

Closed

Description

@elad-yosifon

Code Example:

struct X {
  #[serde(skip_serializing_if = "Option::is_none")]
  y: Option<String>,
  z: Option<i8>
}

Issue Description:

while trying to serialize an instance such as X { y: None, z: Some(0)} using Writer::append_ser(..), it panics with an index-out-of-bounds error pointing to: #/src/ser_schema.rs:376:45

RCA:

  • Serde allows for field skipping using the skip_serializing_if directive.
  • current implementation assumes that schema field count matchs the number of serializer.serialize(..) calls 100%.
  • Use of unsafe random-access on a vec, panics when the assumption breaks.

Activity

  1. added 2 commits that reference this issue on Jul 16, 2025
    e7984ee
    6764f50
  2. added 3 commits that reference this issue on Jul 22, 2025
    27bc8ae
    cec6e27
    4a19a1b
  3. added a commit that references this issue on Jul 24, 2025
    673bec2
  4. added this to the 0.20.0 milestone on Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions