pdflatex not working on Android 11 beta 3 #50
Comments
Thanks! According to https://developer.android.com/preview/behavior-changes-all#fdsan the fdsan behaviour changed in android 11 to give an error instead of just a warning. The pdflatex.log unfortunately does not contain the fdsan error, could you paste the last ~5 lines before the I'll look into booting up android 11 in an emulator.. |
Please see the attached script file of the pdflatex run. |
Btw: The behaviour is still repoducible on the released Android 11. |
@StrangeGranddad could you try capturing a logcat when running the dumping command: |
Yes, of course. Find the logcat attached, hth. |
Oh, I just had this bug I thought I was the only one I was becoming nuts Error log
|
With a debug build of texlive-bin we get this backtrace from gdb when running
Fixing it requires deep diving into the code, seems fairly hard to detect where and why it happens. I'll send an email to the texlive mailing list and ask for help. |
Here's a minimal program, condensed from texlive source, that reproduces the problem #include <zlib.h>
#include <stdio.h>
int open_output(FILE **f_ptr, char *mode) {
*f_ptr = fopen ("test.gz", mode);
return *f_ptr != NULL;
}
#define wopenout(f) (open_output ((FILE**)&(f), "wb") \
&& (f = gzdopen(fileno((FILE*)f), "wb")))
int main() {
gzFile fp;
wopenout(fp);
gzclose(fp);
} Compiling with clang-11 as in
Working program: #include <zlib.h>
#include <stdio.h>
int open_output(FILE **f_ptr, char *mode) {
*f_ptr = fopen ("test.gz", mode);
return *f_ptr != NULL;
}
void wopenout (gzFile f) {
open_output ((FILE**)&(f), "wb");
f = gzdopen(fileno((FILE*)f), "wb");
}
int main() {
gzFile fp;
wopenout(fp);
gzclose(fp);
} |
I opened an issue in google's issue tracker: https://issuetracker.google.com/issues/184380442 Let's hope it gets some attention. @StrangeGranddad are you using stock android? |
I forgot to check return value of open_output. If I add that:
I get the fdsan error for the function implementation as well, so I suppose there is a real fdsan issue here. |
With the if guard added it looks like the issue is that the code is gzclose'ing even if gzopen was not run: #include <zlib.h>
#include <stdio.h>
int open_output(FILE **f_ptr, char *mode) {
*f_ptr = fopen ("test.gz", mode);
return *f_ptr != NULL;
}
void wopenout (gzFile f) {
if (open_output ((FILE**)&(f), "wb")) {
/* this is not run if open_output failed */
f = gzdopen(fileno((FILE*)f), "wb");
}
}
int main() {
gzFile fp;
wopenout(fp);
/* this is always run */
gzclose(fp);
} |
It also has to do with optimization level. With Changing the code so that gzclose is only run if fp is not NULL seem to work for this small example, but not in the actual texlive code unfortunately. If I do that in texlive I get a slightly different backtrace: #0 0xb630f9e8 in fdsan_error(char const*, ...) () from /apex/com.android.runtime/lib/bionic/libc.so
#1 0xb630f6fe in android_fdsan_close_with_tag () from /apex/com.android.runtime/lib/bionic/libc.so
#2 0xb630fd6e in close () from /apex/com.android.runtime/lib/bionic/libc.so
#3 0xb6163afc in gzclose_w (file=0xb6c86320) at /home/builder/.termux-build/zlib/src/gzwrite.c:661
#4 0xb61614f6 in gzclose (file=0xb6c86320) at /home/builder/.termux-build/zlib/src/gzclose.c:21
#5 0x7f56ad40 in storefmtfile () at pdftexini.c:3587
#6 0x7f570984 in mainbody () at pdftexini.c:5658
#7 0x7f560a40 in main (ac=<optimized out>, av=<optimized out>) at /home/builder/.termux-build/texlive-bin/src/texk/web2c/lib/texmfmp.c:1112 |
Comparing the assembly of the Compiling with
After initializing gzFile to null as suggested the error is gone again for the function-implementation of wopenout, but not for the macro-implementation of wopenout. When replacing the wopenout macro with a wopenout function in texlive pdftex cannot open the fmtfile:
which probably means that I have made an error in the patch: --- ./texk/web2c/texmfmp.h.orig 2021-04-04 09:21:49.681023734 +0000
+++ ./texk/web2c/texmfmp.h 2021-04-04 09:27:51.274404368 +0000
@@ -266,14 +266,20 @@
#define bopenout(f) open_output (&(f), FOPEN_WBIN_MODE)
#define bclose aclose
#ifdef FMT_COMPRESS
+#include <zlib.h>
/* f is declared as gzFile, but we temporarily use it for a FILE *
so that we can use the standard open calls */
#define wopenin(f) (open_input ((FILE**)&(f), DUMP_FORMAT, FOPEN_RBIN_MODE) \
&& (f = gzdopen(fileno((FILE*)f), FOPEN_RBIN_MODE)))
-#define wopenout(f) (open_output ((FILE**)&(f), FOPEN_WBIN_MODE) \
- && (f = gzdopen(fileno((FILE*)f), FOPEN_WBIN_MODE)) \
- && (gzsetparams(f, 1, Z_DEFAULT_STRATEGY) == Z_OK))
+static inline int wopenout(gzFile f) {
+ if (open_output ((FILE**)&(f), FOPEN_WBIN_MODE)) {
+ f = gzdopen(fileno((FILE*)f), FOPEN_WBIN_MODE);
+ if (f)
+ return gzsetparams(f, 1, Z_DEFAULT_STRATEGY) == Z_OK;
+ }
+ return 1;
+}
#define wclose(f) gzclose(f)
#else
#define wopenin(f) open_input (&(f), DUMP_FORMAT, FOPEN_RBIN_MODE)
#define wopenout bopenout maybe there's some other error in wopenout.. Haven't gotten any response on the mailing list yet. |
Hi! Not surprisingly, I confirm the issue on Galaxy Tab s6. I have noticed that in the macro
which, I guess, means that the assignment was successful. In the function, |
@panbroggi thanks for testing. Using
Which makes sense, a macro is expanded so Proper "fix" (in the sense that fdsan would be happy) here would be re-writing the code so that the file is opened without the gzFile -> FILE casting, so that we keep track of one fd and, I suppose, another gzFile parameter. Have not had time to dig into it unfortunately. Also, as an alternative fix/workaround have a patch by @xeffyr for disabling fdsan, but I have not found a suitable place to insert it in texlive. |
I see. However, according to gzdopen, it may be clearer to set it to It might be a naive approach, but would a combined macro + function solution work? I mean, by passing the pointer one should effectively modify
Also, thanks a lot for working on this. I am not able to test and run these modifications by myself, I'm sorry. What should I do in order to do these tests? |
Sorry for dropping the ball here
To test you either need to compile texlive with the modifications on device, or cross-compile from the docker image. In any case, it will probably be easier to add a patch like the one for emacs, just need to find where to add it |
In short, we cannot use TeXLive on android 11. One of the worst operating systems ever born! |
I mean, it's just propietary so issues may happen |
@Kreijstal wrote:
No, all the more reason there should be no bugs! ..and this is not properly e bug but a wrong design.. |
@Grimler91 wrote:
Any chance of seeing this problem fixed? |
Add
into |
Please try texlive-bin 20210325 when the build for termux/termux-packages@d1199c0 finishes. |
That's wonderful. I tested
Both
|
@panbroggi thanks for testing! What is the full output you get? Could just mean that the lualatex.fmt failed to generate for an unrelated reason, or that it needs a similar patch |
It seems there are still issues
Maybe we need instructions for a complete transiction from 2020 to 2021. I installed TeXLive with the |
@angelog0 please try deleting the format file |
@Grimler91 here is the log, it's fdsan again (which can sound reassuring now). |
Ok @Grimler91 and @panbroggi , now it works but I suspect there are others |
Fixes termux/science-packages#50. With this we can generate the pdflatex format file, and compile tex files with pdflatex. There might very well be other formats/engines that still trigger the sanitizer.
@angelog0 do a backup of |
@Grimler91, I did the following which does not seem to work:
Other suggestions? BTW, should you update to TL 2021 the |
@Grimler91, I think you have to release ...unless you have a better, and secure, alternative... ..maybe after #72 is fixed.. |
After you released the |
@angelog0 great, thanks for testing! |
Problem description
Hello,
this is a fresh install of termux on a Pixel 4 with the current Android 11 beta 3 / release candidate.
After installing texlive-full I tried running pdflatex on a document created on the same phone before doing the update to beta 3 (from Android 10).
The result ends in
Steps to reproduce
Expected behavior
I expected to run pdflatex on a syntactically correct .tex-file without error, resulting in a .pdf-file.
Additional information
Please find the content of /data/data/com.termux/files/home/.texlive2020/texmf-var/web2c/pdftex/pdflatex.log attached as advised in https://www.reddit.com/r/termux/comments/ib8j7z/pdflatex_not_working_on/
pdflatex.log
The text was updated successfully, but these errors were encountered: