Page MenuHomeFreeBSD

swab: Fix implementation to support overlapping copies
ClosedPublic

Authored by imp on Dec 30 2024, 8:39 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Feb 4, 8:19 PM
Unknown Object (File)
Sun, Jan 26, 6:03 AM
Unknown Object (File)
Jan 15 2025, 6:40 PM
Unknown Object (File)
Jan 15 2025, 12:17 AM
Unknown Object (File)
Jan 13 2025, 7:01 AM
Unknown Object (File)
Jan 13 2025, 6:24 AM
Unknown Object (File)
Jan 13 2025, 1:43 AM
Unknown Object (File)
Jan 12 2025, 4:42 PM
Subscribers
None

Details

Summary

A number of image processing packages assume that swab() can handle to
and from being the same. However, POSIX.1 states that overlapping
buffers produces undefined results. Our old implementation would produce
coherent results, but the recent change to the musl-inspired code does
not. Since there's complaints in the forums for these image processing
packages for musl and now FreeBSD, update the algorithm to just read a
word at a time and bswap16 the results. All FreeBSD's architecutres
support unaligned access in userland, and swab is not used in the kernel
(g_part_apm has its own copy), so opt for even simpler code that's
easier to understand. This makes the overlapping behavior match i386 again,
since its assembler routine for swab handles overlapping correctly.

PR: 283698
Sponsored by: Netflix

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

imp requested review of this revision.Dec 30 2024, 8:39 PM
imp created this revision.

This looks great to me -- thanks!

This revision is now accepted and ready to land.Dec 31 2024, 12:12 AM