Skip to content

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

@elad-yosifon

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.

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