File descriptor error for pdflatex.fmt creation on android 11

Henrik Grimler henrik at grimler.se
Fri Apr 9 23:01:07 CEST 2021


Hi Karl,

Thanks for the feedback!

On Thu, 2021-04-08 at 19:39 -0600, Karl Berry wrote:
> From your descriptions, all I can guess is that this is some kind of
> (strange) Android problem being caused by this concept of "sanitizing
> file descriptors", whatever that actually means technically.
> 
> I know of no reason why a macro vs. a function would make a difference
> except for bugginess. 

I still do not know why the function and macro behaves differently, but
I have at least learnt a bit more what the sanitizer does by
investigating similar errors for other programs.
The sanitizer tries to make sure we close streams/files with the stream
handle(s) obtained through fdopen (or similar, i.e. gzdopen) and not by
using the file descriptor. 

Here's another minimal example that triggers the error:
```
#include <stdio.h>
#include <unistd.h>
int main() {
  FILE *fd = fdopen(fileno(stdout), "w");
  /* not ok: close(fileno(stdout)); */
  /* not ok: fclose(stdout); */
  /* ok: */ fclose(fd);
}
```
Trying to close stdout without using `fd` (as in the first two "not ok"
commands) triggers the error, while `fclose(fd);` works, so could be
how fopen() and gzdopen() are run.

Another possibility is that the sanitizer does not like that
wopenout/w_open_out is called in a while loop, since this means fopen()
and gzdopen() potentially are called multiple times. 

> All this code has been around for decades (modulo
> the fmt compression, which is only a couple years old), without
> problems, so I'm not at all inclined to mess with it to try to work
> around self-inflicted Android issues.

Yeah, the (pdf)tex.web code is fine. Android just does not like how the
compression is done in texmfmp.h. Frankly, I do not quite understand
how the existing (compression) wopenout macro works, with multiple
steps and gzFile->FILE casting. So, I will try to simplify this into
something I do understand and see if I can make sense of the issue on
android.

Hopefully we can revisit this when I have some code that works and that
looks alright. 

Best regards,
Henrik Grimler



More information about the tex-live mailing list.