Skip to content

Fix partial writes for coredumps larger than 2 GiB - #647

Open
bdrung wants to merge 1 commit into
canonical:mainfrom
bdrung:fix-os.write
Open

Fix partial writes for coredumps larger than 2 GiB#647
bdrung wants to merge 1 commit into
canonical:mainfrom
bdrung:fix-os.write

Conversation

@bdrung

@bdrung bdrung commented Aug 18, 2026

Copy link
Copy Markdown
Member

Python's os.write() is a low-level POSIX call that directly maps to the write(2) system call. The write(2) man page says:

On Linux, write() (and similar system calls) will transfer at most 0x7ffff000 (2,147,479,552) bytes, returning the number of bytes actually transferred.

Because os.write() does not handle looping, writing raw bytes coredumps larger than 2 GiB results in truncated files of exactly 0x7ffff000 bytes, which are then reported as corrupted by gdb.

In data/apport loop over os.write until the whole coredump is written since that scripts operate on low level. In apport.report use os.fdopen to operate on a high-level file object to safely write all bytes.

Bug: https://launchpad.net/bugs/2109979

Python's `os.write()` is a low-level POSIX call that directly maps to
the `write(2)` system call. The `write(2)` man page says:

> On Linux, write() (and similar system calls) will transfer at most
> 0x7ffff000 (2,147,479,552) bytes, returning the number of bytes
> actually transferred.

Because `os.write()` does not handle looping, writing raw `bytes`
coredumps larger than 2 GiB results in truncated files of exactly
0x7ffff000 bytes, which are then reported as corrupted by gdb.

In `data/apport` loop over `os.write` until the whole coredump is
written since that scripts operate on low level. In `apport.report` use
`os.fdopen` to operate on a high-level file object to safely write all
bytes.

Bug: https://launchpad.net/bugs/2109979
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.50%. Comparing base (7ce5916) to head (68dcd1b).

Files with missing lines Patch % Lines
data/apport 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #647      +/-   ##
==========================================
+ Coverage   84.48%   84.50%   +0.01%     
==========================================
  Files         106      106              
  Lines       21044    21047       +3     
  Branches     3192     3194       +2     
==========================================
+ Hits        17780    17786       +6     
+ Misses       2790     2788       -2     
+ Partials      474      473       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant