Skip to content

TraceEvent <-> u32 conversion is overlapping and lossy #48

@mooori

Description

@mooori

For example, if code in AssertionFailed(code) happens to be 0xfc it is converted to 0xfc, same as FrameEnd. There seems to be no restriction on the values that code can take.

pub fn as_u32(self) -> u32 {
match self {
Self::FrameStart => TRACE_FRAME_START,
Self::FrameEnd => TRACE_FRAME_END,
Self::AssertionFailed(None) => 0,
Self::AssertionFailed(Some(code)) => code.get(),
Self::Unknown(event) => event,
}
}

Not all TraceEvent variants can be constructed from u32:

impl From<u32> for TraceEvent {
fn from(raw: u32) -> Self {
match raw {
TRACE_FRAME_START => Self::FrameStart,
TRACE_FRAME_END => Self::FrameEnd,
_ => Self::Unknown(raw),
}
}
}

Impact

Might not cause any issues as assertion failures are handled separately. However TraceEvent and the conversion methods are public and hitting that issue would cause confusion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions