hoene / libmysofa

Reader for AES SOFA files to get better HRTFs
Other
137 stars 73 forks source link

Safe limit increase #221

Closed ThreeDeeJay closed 1 month ago

ThreeDeeJay commented 1 month ago

I've seen many reports of users having issues loading even moderately-sized SOFAs in software that uses libmysofa, due to the current limit. Even for OpenAL Soft's makemhr converter I had to use my fork where I removed the limit, but the dev suggested a better, safer alternative which I figured I'd share here in case it's a viable option:

Looks like it may need an overflow check too. Something like

if(elements <= 0 || size <= 0 || elements > INT_MAX/size)
return MYSOFA_INVALID_FORMAT;

I don't know how this check in specific relates to the file or dataset size, but at least the result of elements * size can't go far above 2.1 billion, or else it'll overflow and become undefined behavior. Expanding that would need more work to avoid signed ints, where those kinds of changes tend to need farther reaching changes since those variables may interact with other variables that may not be happy when they're different types.