Skip to content

fix(libkernel): fail write with EINVAL for a size above SSIZE_MAX - #4818

Closed
Gashrod1 wants to merge 1 commit into
boykopovar:mainfrom
Gashrod1:fix/libkernel-write-oversized-einval
Closed

Gashrod1 wants to merge 1 commit into
boykopovar:mainfrom
Gashrod1:fix/libkernel-write-oversized-einval

Conversation

@Gashrod1

Copy link
Copy Markdown
Contributor

What

write_nid_postfix threw std::invalid_argument when the byte count did not fit in ssize_t, which ends the process. FreeBSD's sys_write returns EINVAL for it before looking up the descriptor (sys/kern/sys_generic.c: if (uap->nbyte > IOSIZE_MAX) return (EINVAL);, where IOSIZE_MAX is SSIZE_MAX with the default debug.iosize_max_clamp=0). write now returns -1 with errno 22 for such a count, for any descriptor.

guest_filesystem checks write with SIZE_MAX on a pipe and with SSIZE_MAX + 1 on descriptor -1 (EINVAL, not EBADF). It fails on main and passes with the change.

Tested

Linux (Arch, GCC), Release, BUILD_TESTING=ON, based on main ee4962190: guest_filesystem aborts on main and passes with the change (3 runs); full build and full ctest pass. Windows (WinLibs MinGW-w64 GCC 15.2.0 r7, NVIDIA RTX 5060), Release, BUILD_TESTING=ON: full build and full ctest pass (1018 tests, the same 7 skipped as on main). No title or homebrew run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

@CnRJay CnRJay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change matches FreeBSD's sys_write. Note that #4929 makes the same size < 0 → EINVAL change in write_nid_postfix (as part of a three-call fix in Stdio.cpp), so the two will conflict on that line. Agreeing with its author which one carries it, and listing it under Depends on, would save a rebase. Your test of SSIZE_MAX + 1 on descriptor -1 (EINVAL before EBADF) is a case #4929 doesn't cover, so it's worth keeping either way.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants