-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bus error with PDO Firebird on RPI with 64 bit kernel and 32 bit userland #10908
Comments
I can reproduce this. It's a misaligned memory access. I'll work on a fix and a test case and submit a PR soon. |
…l and 32 bit userland The alignment of sqldata is in most cases only the basic alignment, so the code type-puns it to a larger type, it *can* crash due to the misaligned access. This is only an issue for types > 4 bytes because every sensible system requires an alignment of at least 4 bytes for allocated data. Even though this patch uses memcpy, the compiler is smart enough to optimise it to something more efficient, especially on x86. This is just the usual approach to solve these alignment problems. Actually, unaligned memory access is undefined behaviour, so even on x86 platforms, where the bug doesn't cause a crash, this can be problematic. Furthermore, even though the issue talks about a 64-bit kernel and 32-bit userspace, this doesn't necessarily need to be the case to trigger this crash. Test was Co-authored-by: rvk01
Thanks for picking this up so fast. I appreciate that greatly. I tried to test your changes as good as I could (I'm not that familiar with compiling PHP) but I've managed to create a pdo_firebird.so for the newer PHP version (I didn't know which switched I needed to use for a complete install). The BIGINT and NUMERIC work (the last you added this morning). I'm not sure how far you are but it seems that TIMESTAMP also has a problem (don't know if you added that one already). (CASTing a TIMESTAMP to DATE works) |
Thanks for testing. I'll handle timestamp now too and update the test to check timestamp. |
Sorry... I've got another one... BLOB fields have the same problem :( Can there still be any other larger fields we missed? (Newer Firebird also has INT128, but I don't use that yet, not sure if you got that one too) |
No need to apologize, on the contrary, it's good that you find these issues! I don't see INT128 in our Firebird code, so maybe we should create a feature request to add support for that. |
Ah, Ok. I still maintain Firebird 2.5 code so I have no need for INT128 support... yet :) The complete list of datatypes is here (but you probably already know): I'll test it again when I see the changes in your tree. (I'll include all the fields I use then) I guess it'll take some time before these changes trickle down to production version, so I'll use my own compiled pdo_firebird.so version until then ;) Thanks. |
Thanks for the list. And no I didn't actually know this, in fact, I have never used Firebird until I started working on your issue :P
My tree has the fixes for the remaining issues now. :)
Sounds good! |
Thanks. For now it seems to work perfect. |
Cool. Just make sure your current git HEAD is commit 897352d which is the latest commit. It has one additional fix and I had committed that after posting my comment above. |
I'm still relative new to git but I think I have the latest (also got it with a pull). git log -1 So I guess I have the latest :) Edit: Ah. The numbers here are automatically converted to commit links :) |
Yep looks like you got the correct commit. While you can hack that version number to allow 8.1 code on 8.2, it's best to rebase the patch on 8.2 so that there are no potential API mismatches. Although I think the chance is low it causes issues in this particular case. |
You are correct. But because I'm still learning git and merging etc, it was easier for me to just hack your complete 8.1 version for now. Even with a complete PHP 8.2 merged with this fix, I couldn't put this in production because I'm still unsure about all the switched I need to use for ./configure on a RPI4. So for now I just used ./configure --disable-opcache-jit --without-pcre-jit --with-pdo-firebird=shared --host=arm-linux --build=arm --target=arm (which is probably different from the normal production version) But I could take the latest PHP 8.2 (with fix) and recompile so the latest API is used (although the changes only seem to be in pdo_firebird. But maybe some other code is used too.) I'll recompile this weekend (if I can figure out git :) ). |
* PHP-8.1: Fix GH-10908: Bus error with PDO Firebird on RPI with 64 bit kernel and 32 bit userland
* PHP-8.2: Handle indirect zvals in SplFixedArray::__serialize Fix GH-10908: Bus error with PDO Firebird on RPI with 64 bit kernel and 32 bit userland
It turns out that the version of Firebird influences the test in terms of supported data types. On Windows on 8.2 we seem to be using a different version than on 8.1. Fix it by amending the test. The core issue is still tested in the test, it's just that not all datatypes are tested anymore (which isn't strictly necessary anyway).
Description
With a simple apt-get upgrade on my RPI 4 it was upgraded to a 64 bit kernel automatically :(
uname -a
Linux space01 6.1.19-v8+ #1637 SMP PREEMPT Tue Mar 14 11:11:47 GMT 2023 aarch64 GNU/Linux
Now the SELECT of a BIGINT and NUMERIC(18,3) always results in a "Bus error".
Switching back to the 32 bit kernel (with arm_64bit=0 in /boot/config.txt) it works again:
uname -a
Linux space01 6.1.19-v7l+ #1637 SMP Tue Mar 14 11:07:55 GMT 2023 armv7l
But I can't use the 32 bit kernel anymore because of multiple out of memory errors.
(with 8GB there is too little space in the lower memory)
Casting a BIGINT to INTEGER and a NUMERIC(18,3) to NUMERIC(9,3) works too.
(It seems from NUMERIC(10,3) and above the error occurs again.)
Reproduce with the following code (command for creating testdatabase is in the comments):
Resulted in this output:
But I expected this output instead:
PHP Version
PHP 8.2.4
Operating System
Raspbian GNU/Linux 11 (bullseye)
The text was updated successfully, but these errors were encountered: