Skip to content

Native backend uses physical attachment filename for hard crashes, instead of the name passed to USentryLibrary::CreateSentryAttachmentWithData() #1933

Description

@kjp-einosuke

Description

On Windows, the native backend can use the wrong attachment filename after a hard crash.

The application adds a file attachment and then sets a custom filename:

sentry_attachment_t *attachment =
    sentry_attach_file("C:\\temp\\archive-2026-07-31.zst");
sentry_attachment_set_filename(attachment, "game.log.zst");

A normal event shows game.log.zst, as expected. A hard-crash event shows archive-2026-07-31.zst, which is the basename of the physical path.

UE ensure events do not have this problem. They use the normal event path and read the current in-memory attachment. Only hard-crash events use the stale attachment manifest.

The cause is the order of these operations:

  1. sentry_attach_file(path) adds the attachment to the global scope.
  2. SENTRY_WITH_SCOPE_MUT immediately flushes the scope (sentry_core.c:2040-2068, sentry_scope.h:162-164, and sentry_scope.c:179-186).
  3. The native backend writes __sentry-attachments before the custom filename is set (sentry_backend_native.c:729-780, especially lines 757-760).
  4. sentry_attachment_set_filename changes the in-memory attachment, but it does not flush the scope (sentry_attachment.c:63-80).
  5. A normal event reads the current in-memory attachment and uses the custom filename (sentry_attachment.c:163-169 and sentry_envelope.c:722-751).
  6. The crash daemon reads the earlier attachment manifest and uses the physical basename (sentry_crash_daemon.c:3614-3658).

A later scope change can rewrite the manifest and hide the problem. Therefore, the result can depend on timing.

The Sentry UE wrapper calls these APIs in this order in GenericPlatformSentrySubsystem.cpp:411-419. The Windows implementation has the same order in MicrosoftSentrySubsystem.cpp:77-84. Project code only supplies the physical path and custom filename. The affected processing after that point is Sentry code.

When does the problem happen

  • During build
  • During run-time
  • When capturing a hard crash

Environment

  • OS: All platforms where we use the Sentry native backend
  • Compiler: MSVC 14.38.33130
  • sentry-native version: 0.16.0
  • Sentry UE5 plugin version: 1.18.0

Steps To Reproduce

  1. Initialize sentry-native with SENTRY_BACKEND=native.
  2. Create C:\temp\archive-2026-07-31.zst.
  3. Add the attachment and set a different filename:
sentry_attachment_t *attachment =
    sentry_attach_file("C:\\temp\\archive-2026-07-31.zst");
sentry_attachment_set_filename(attachment, "game.log.zst");
  1. Capture a normal event. Confirm that its attachment filename is game.log.zst.
  2. Repeat the setup.
  3. Do not make another scope change after sentry_attachment_set_filename.
  4. Cause a hard crash.
  5. Inspect the attachment filename in the hard-crash event. It is archive-2026-07-31.zst instead of game.log.zst.

Log output

No relevant error is written to the log.

Expected: Ensure events, other normal events, and hard-crash events use game.log.zst.

Actual: Ensure events and other normal events use game.log.zst. Hard-crash events use archive-2026-07-31.zst.

Metadata

Metadata

Assignees

Labels

Attachmentsissue relates to attachments, i.e. screenshots, view hierarchy, file attachmentsBugsomething isn't working as it shouldNativeplatform label

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions