I'm debugging the commandtex of TeX Live 2019.
Shown as above, if you type:
./tex -inihI\&VeThere will be a segment fault. Note that you need ah.tex under the same directory astex and there is one character\ inh.tex.
My question is what does cmdI do? It seems it fails to open a file because there is an invalid sequence\&V afterI.And what does cmde do? I know It passes the file pointer tofclose() that failed to be initialized byI and the leads to the segment fault.
Thanks!
- 1Welcome to TeX.SX! Donald already explained why the TeX errors happen. But to reproduce the segfault with
tex(not-ini) you can write\?instead of\and\&. More generally, the segfault happens if you are running TeX on a file, and pressEin the menu while TeX is scanning the input ofI. Interesting find!Phelype Oleinik– Phelype Oleinik2020-07-03 03:33:04 +00:00CommentedJul 3, 2020 at 3:33 - It seems at first glance like a bug in TeX. A have no time for studying this issue in TeX sources now. If it is true bug then congratulations: you have found the bug in TeX 3.14159265.wipet– wipet2020-07-03 06:58:44 +00:00CommentedJul 3, 2020 at 6:58
- @barbarabeeton May be you know the term when D. Knuth opens the folder with bug reports of TeX 3.14159265...wipet– wipet2020-07-03 07:09:29 +00:00CommentedJul 3, 2020 at 7:09
3 Answers3
Running TeX with the-ini flag means that you're running without any preloaded format. You don't get anything but primitive commands which means that\ and\& aren't defined. So that's why you're getting the errors. Do you really want to be running iniTeX?
i means insert the text following at the point that the error occurred.x is the usual quit command.e in theory will stop and then open an editor at the error point. I'm guessing this is missing some implementation/configuration which is why you're getting the segmentation fault. These are just some of the interactive error handling commands that TeX provides. SeeThe TeXbook for more information about how these work. I've never really bothered with them. They made a lot of sense in the early 80s when computers were slow and compute time expensive but even by 1986 when I first started using TeX the program ran fast enough that it was generally more sensible to just use x to stop TeX, fix the error in the input file and continue.
- The weird thing is that TeX seems to consistently segfault if you type
ewhile reading the input ofi...Phelype Oleinik– Phelype Oleinik2020-07-03 03:22:47 +00:00CommentedJul 3, 2020 at 3:22 - Thanks a lot. But I'm a little bit confused about "i". Will "i" insert the text to the file h.tex? Or do you mean "i" just insert a text to a buffer?潇洒张– 潇洒张2020-07-03 03:59:28 +00:00CommentedJul 3, 2020 at 3:59
- No, it inserts the characters into the stream being read by the current run, so is not useful for fixing an error. It could be useful for diagnosing an error that you aren't sure of, but as DH says, it usually makes more sense to edit the input file and run TeX again.Donald Arseneau– Donald Arseneau2020-07-03 05:18:45 +00:00CommentedJul 3, 2020 at 5:18
- @DonaldHosek Did you get sucked into this quagmire by Coronavirus lockdowns too?Donald Arseneau– Donald Arseneau2020-07-03 05:21:04 +00:00CommentedJul 3, 2020 at 5:21
- 2@DonaldArseneau don't think of it as being sucked into a quagmire, think of it as being rescued from the primordial swamp that is c.t.tDavid Carlisle– David Carlisle2020-07-03 08:30:46 +00:00CommentedJul 3, 2020 at 8:30
Congratulations, you have found the bug in TeX.
Edit I did deeper inspection about this issue when I returned from my vacation and I found: the bug is in the C implementation of TeX, not in the TeX itself (coded by D. Knuth). So, the following paragraph (given by me a few days ago) is not explicitly true:
The last revision of TeX (version 3.14159265) was done by D. Knuth in 2014, next revision will be in the end of 2020. If you send this bug-report you can get a check for a small piece in dollars by D. Knuth. Of course, this is true only if your bug report will be processed as real bug of TeX. How to do the bug report is described athere in section Errata.
Description of the bug: If we invoke an error (undefined\ in your example), then theI option is possible. If we useI option with a line with next error (undefined\& in your example) and theI line is not closed at this place (theV follows in your example) then this second error offers all options includingE option. But usingE option causes that TeX crashes, because the file name is zero in this case.
In detail:I option in § 84 of TeX web runs the code from § 87 where the procedure begin_file_reading is processed. This procedure is in § 328 and here is:name := 0. Thename is macro defined in § 302:name = cur_input.name_field. Now, we can return to § 84 where theE option is solved. It creates the file name (which may be sent to an editor) frominput_stack[base_ptr].name_field but this is the same ascur_input.name_field and it was set to zero. We have no file name here but zero. TeX implementation based on C crashes with segmentation fault because we want to open the file with buggy file name.
Edit: When I did experiments withtex.web code and I deactivated the system dependent code given afterE option then the correct answer is here:You want to edit file <correct name> at line <correct number>. The bug is in thelib/texmfmp.c at line 2579 where the opened files are closed and the maximal index of opened files are read frominopen global variable. This variable is incremented whenI option is used but no new file is opened in such case. So, we cannot close non-existent file inlib/texmf.c. Knuth says in §304: "The global variablein_open is equal to the value of the highest non-token-list level." It means that it is not always the number of currently opened files. Knuth's code and his comments in the code are correct here, bug is in the system dependent implementation.
- At the point of the first error message,
\jobnamehas been set toh.egreg– egreg2020-07-03 13:07:26 +00:00CommentedJul 3, 2020 at 13:07 - @egreg the file name h is irrelevant. You can insert
\blain your document (the name of the document and the format are irrelevant). When the prompt about undefined\blaoccurs then inseti\buff X. When the prompt about undefined\buffoccurs then inserte. The result is segmentation fault.wipet– wipet2020-07-03 13:13:25 +00:00CommentedJul 3, 2020 at 13:13 - Maybe you can make it clear in your answer.egreg– egreg2020-07-03 13:29:57 +00:00CommentedJul 3, 2020 at 13:29
- But it crashed on fclose() with uninitialized file pointer as the argument. In this case there is only one file: h.tex. But inopen was 2 when it tried to close all files. So it tried to close inputfile[1] and inputfile[2] in a for loop and inputfile[2] was uninitialized.潇洒张– 潇洒张2020-07-03 14:23:59 +00:00CommentedJul 3, 2020 at 14:23
- 1@潇洒张 I corrected the term of bug report: theend of this year. Please, tell me if you prepare this bug report. If no, then I will try to do it. But you found this bug, this is much more correct if the honor will go to you. I have only analyzed this big from technical point of view. But I wouldn't think of trying the
Eoption in the context ofIoption.wipet– wipet2020-07-03 20:24:18 +00:00CommentedJul 3, 2020 at 20:24
Original poster: as with your other report ... if you ever see this, please email me, karl at tug.org, so we can give you proper credit in our report to Don Knuth. (We believe there is a bug in tex.web as well as in web2c; the tex.web code can be induced to print a bogus filename in the "You want to edit ..." message.)
Regarding begin_file_reading, it is, shall we say, suboptimally named. What it really does is "begin a level of input" - either from a file or from terminal interaction.
I just committed a fix (hopefully) for this to TeX Live, r55857 (http://tug.org/svn/texlive/trunk/Build/source/texk/web2c/lib/texmfmp.c?r1=53078&r2=55857&pathrev=55857). It involves having to look at all elements of input_stack[] to discern whether a given entry in input_file[] is actually a file, or a non-file resulting from terminal interaction. Before, we simply closed everything in input_file[], but that was wrong.
Regarding "the end of this year" - please send any and all Knuthian bug reports to me or tex-k at tug.org as soon as possible! Do not wait for December 31. My unofficial deadline is November 1. All reports have to be vetted before they go into the pile for Knuth, and it takes time. More info:https://tug.org/texmfbug.
Thanks to all.
You mustlog in to answer this question.
Explore related questions
See similar questions with these tags.



