Skip to content

Conversation

@fabienr
Copy link

@fabienr fabienr commented Dec 28, 2025

Just like Apple, OpenBSD doesn't provide malloc.h header and already defines __assert() from the base system.
Hopefully the offending __assert() which doesn't have the same arguments isn't used, otherwise it would error out.

The cpp compiler on OpenBSD is more strict and raise an error on invalid operands to binary expression.
('uintptr_t' (aka 'unsigned long') and 'std::nullptr_t')
48 | if (desiredTarget != NULL)
| ~~~~~~~~~~~~~ ^ ~~~~

Finally, Shipwright has the same memory/alignment issue seen in Starship (which already have a workaround guarded by SANITIZE_ADDRESS). See HarbourMasters/Starship#238.

Build Artifacts

@serprex
Copy link
Contributor

serprex commented Dec 30, 2025

Please run run-clang-format.sh

@fabienr
Copy link
Author

fabienr commented Dec 30, 2025

I fixed the offending line by hand, will try run-clang-format.sh. Does this also apply to Starship, libultraship ... ?

The clang version I have 19.1.7, after runing run-clang-format.sh bring in more changes :

-                        if (((synthState->samplePosInt * 2) + (samplesLenAdjusted)*2) < audioFontSample->size) {
-                            bytesToRead = (samplesLenAdjusted)*2;
+                        if (((synthState->samplePosInt * 2) + (samplesLenAdjusted) * 2) < audioFontSample->size) {
+                            bytesToRead = (samplesLenAdjusted) * 2;

@Malkierian
Copy link
Contributor

We use clang 18.0.6 specifically, that's why it made more changes than it fixed. It does apply to 2ship and LUS as well, not sure about Starship or Spaghetti Kart.

aligned = ALIGN16((nFramesToDecode * frameSize) + 16);
addr = DMEM_COMPRESSED_ADPCM_DATA - aligned;

#if __SANITIZE_ADDRESS__ || defined(__OpenBSD__)
Copy link
Contributor

Choose a reason for hiding this comment

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

when this is unconditional the audio issue still only happens on OpenBSD I assume

wondering why this can't either be unconditional, or if there's some alignment handling aLoadBuffer should be using instead

which is to say I don't really understand what's happening here, & would appreciate explanation

Copy link
Author

Choose a reason for hiding this comment

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

The SANITIZE_ADDRESS came from Starship.
Check HarbourMasters/Starship@64442db

I'm mainly debugging there (in Starship) atm. But the following principle still stands and both are very similar.

The CODEC_ADPCM uses 9 bytes to decode into 16 samples. The first byte is important as it provides a hint on how to decode the following 8 bytes into 16 samples. Which means we can't decode half of a frame easily.

The function AudioSynth_ProcessNote calculates a number of samples to process but this isn't aligned to frames, thus the need for some math around (which I don't fully understand yet). In some cases this goes wrong and it tries to decode bytes outside the audioFontSample. OpenBSD is more strict so the software will crash early. Note it doesn't crash on all audioFontSample and I guess it's because of how the memory is allocated vs the size of the book which means there is room after the end of buffer and before the end of memory allocated. But still it's an out of bound read overflow.

My hypothesis is you will start noticing choppy audio on Linux if you enable the this check unconditionally.
I do not have Linux at hand so I can't compare easily. Maybe you could add a printf to check if Linux actually triggers the check ? Otherwise, it would mean something else deviated on OpenBSD and led to this crash.

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

does #6089 help? it has some fixes for audio samples

Copy link
Author

Choose a reason for hiding this comment

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

Didn't try the diff yet, it will fix the crash for sure with the extra padding.
From what I remember, it's a matter of a frame so at most 16 samples which are 9 bytes encoded.

Also, it memset to 0 so I'm curious which sound it will produce.
I doubt it will be exactly like intended but maybe ... will test for sure.

Also, this is the place to pre-decode samples in memory, maybe that would be easier (I guess).

Thanks for the hint.

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.

3 participants