Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 910430 - sys-apps/less: broken for some terminfo (e.g. TERM=xterm-direct256) (was: sys-libs/ncurses-6.4_p20230401: some terminfos became broken)
Summary: sys-apps/less: broken for some terminfo (e.g. TERM=xterm-direct256) (was: sys...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal major
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-16 14:10 UTC by Vadim A. Misbakh-Soloviov (mva)
Modified: 2023-07-18 22:19 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info sys-libs/ncurses (file_910430.txt,30.10 KB, text/plain)
2023-07-16 17:40 UTC, Vadim A. Misbakh-Soloviov (mva)
Details
script used to mock-up the Gentoo packages (build-gentoo-ncurses,1.88 KB, application/x-shellscript)
2023-07-18 21:55 UTC, Thomas Dickey
Details
ncurses debugging trace from "demo_terminfo" (demo_terminfo-trace,106.00 KB, text/plain)
2023-07-18 21:59 UTC, Thomas Dickey
Details
out from infocmp ABI 5 versus 6 (infocmp.log,1.12 KB, text/plain)
2023-07-18 22:19 UTC, Thomas Dickey
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vadim A. Misbakh-Soloviov (mva) gentoo-dev 2023-07-16 14:10:01 UTC
(not sure if related to tinfo USE-flag)

After upgrading to =sys-libs/ncurses-6.4_p20230401 I've found that some terminfo definitions became broken.

For example, xterm-direct256, which I used for years, now makes `less` to produce:
```
WARNING: terminal is not fully functional
```
and don't enter alternate screen mode.
`vim9` also doesn't enter altscreen anymore with it.
`mc` - blames that terminal doesn't support 256 colors, despite both terminal application and selected terminfo (xterm-direct256) do support it.
`mtr` also blames `Error opening terminal: xterm-direct256.` and refuses to start.

And so on.

Same behaviour also can be seen with some others terminfos.

(!!!) downgrading to 6.3_p20221203-r2 makes all the things work fine again.


// Probably blocker for https://bugs.gentoo.org/457530


Reproducible: Always
Comment 1 Ionen Wolkens gentoo-dev 2023-07-16 14:17:54 UTC Comment hidden (obsolete)
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-07-16 14:19:34 UTC
emerge --info sys-libs/ncurses, please.
Comment 3 Ionen Wolkens gentoo-dev 2023-07-16 14:20:07 UTC Comment hidden (obsolete)
Comment 4 Ionen Wolkens gentoo-dev 2023-07-16 14:23:47 UTC Comment hidden (obsolete)
Comment 5 kfm 2023-07-16 15:04:23 UTC
Thus far, I've reproduced the reported behaviour by setting TERM=xterm-direct256 in the course of executing less-633, mtr-0.95 and vim-9.0.1503. Upgrading from 6.4_p20230401 to 6.4_p20230527 (which currently masked) did not alter said behaviour.

I tried the exact same tests in Arch (ncurses 6.4_20230520-1, less 1:633-1, vim 9.0.1676-1), which does not exhibit any issue. Why is unclear to me.

In all cases, I used xterm as the terminal emulator, not that it ended up mattering.
Comment 6 kfm 2023-07-16 15:32:07 UTC
On a whim, I prevented the ebuild from applying any patches, which rather bluntly rectifies the issue.
Comment 7 Vadim A. Misbakh-Soloviov (mva) gentoo-dev 2023-07-16 17:40:23 UTC
Created attachment 865609 [details]
emerge --info sys-libs/ncurses

(In reply to Sam James from comment #2)
> emerge --info sys-libs/ncurses, please.

Oh, sorry, I've distracted and forgot to attach
Comment 8 kfm 2023-07-17 01:56:57 UTC
Applying only ncurses-6.4-20230107.patch still results in a working build.

Applying ncurses-6.4-20230114.patch on top of that results in a defective build.
Comment 9 kfm 2023-07-17 02:47:23 UTC
May I ask why we have all these patches to begin with? Can we not just pick a snapshot tarball from the following location?

https://invisible-mirror.net/archives/ncurses/current/

It seems to be me that doing would simplify the maintenance burden while also making it less likely for things to go awry.

At the time of writing, Arch's PKGBUILD fetches ncurses-6.4-20230520.tgz, which works fine in so far as this bug is concerned.
Comment 10 Ionen Wolkens gentoo-dev 2023-07-17 03:51:41 UTC
I think(?) the reason it works for Arch is that they're forcing everything to link with the widec version of the libraries.

i.e. if I link less(1) with tinfow rather than tinfo, it seems(?) fine.

So the version/tarball used by Arch is likely still affected, but they just have a setup that doesn't trigger the issue.
Comment 11 Larry the Git Cow gentoo-dev 2023-07-17 22:04:46 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4835fedb1257d15d871c885e19b8fecfff78abfd

commit 4835fedb1257d15d871c885e19b8fecfff78abfd
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2023-07-17 22:02:52 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2023-07-17 22:03:32 +0000

    sys-apps/less: fix tinfo linkage, add LFS
    
    Thanks to ionen and kerframil for doing the hard work here wrt tinfo, just
    doing the then-obvious patch as a result.
    
    Also, while at it, enable large file support.
    
    Closes: https://bugs.gentoo.org/896316
    Closes: https://bugs.gentoo.org/910430
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-apps/less/files/less-633-tinfow.patch | 52 +++++++++++++++++++
 sys-apps/less/less-633-r2.ebuild          | 86 +++++++++++++++++++++++++++++++
 sys-apps/less/less-9999.ebuild            |  8 ++-
 3 files changed, 145 insertions(+), 1 deletion(-)
Comment 12 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-07-17 23:03:34 UTC
Thomas, I was wondering if you had any insight here.

The gist is that less was finding -lncursesw but using -ltinfo (not -ltinfow) because of bad search order, and then `TERM=xterm-direct256 less` errored out.

It's apparently exposed by https://github.com/ThomasDickey/ncurses-snapshots/commit/7144200303b2df93a7441a1b47ae133a56e06ad7.

I assume the mixing is unsupported but I wonder:
- Is there a workaround possible?
- Is there a way to poison ncursesw when building with split tinfo, so that you get some unresolved symbol in there which only tinfow can satisfy? 
- Is this mixture supported? (I assume not, but I have to ask.)

I note https://bugzilla.redhat.com/show_bug.cgi?id=1580323 in the past which was kind of similar.

Anyway, I've sent a fix upstream to less at https://github.com/gwsw/less/pull/403, but I worry about more of these.
Comment 13 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-07-17 23:34:28 UTC
(In reply to Sam James from comment #12)
> Thomas, I was wondering if you had any insight here.
> 
> The gist is that less was finding -lncursesw but using -ltinfo (not
> -ltinfow) because of bad search order, and then `TERM=xterm-direct256 less`
> errored out.
> 
> It's apparently exposed by
> https://github.com/ThomasDickey/ncurses-snapshots/commit/
> 7144200303b2df93a7441a1b47ae133a56e06ad7.
> 
> I assume the mixing is unsupported but I wonder:
> - Is there a workaround possible?
> - Is there a way to poison ncursesw when building with split tinfo, so that
> you get some unresolved symbol in there which only tinfow can satisfy? 
> - Is this mixture supported? (I assume not, but I have to ask.)
> 
> I note https://bugzilla.redhat.com/show_bug.cgi?id=1580323 in the past which
> was kind of similar.
> 
> Anyway, I've sent a fix upstream to less at
> https://github.com/gwsw/less/pull/403, but I worry about more of these.

... or maybe there isn't any mixing, as only tinfo or tinfow is linked at the end, and perhaps the termcap is just broken for tinfo?

(but there's still mixing of headers it seems anyway.)
Comment 14 Thomas Dickey 2023-07-17 23:39:00 UTC
Debian provides just tinfo, which is shared between ncurses/ncursesw.
The calling interfaces are supposed to be compatible.  The ncurses
utilities use the structs internally - other programs don't see those.

I don't see anything odd in the patch, other than perhaps if one was
building the terminal database using an old version of tic, which had
problems with forward-references.

That was before 6.3 (but some of the fixes were in tinfo):

https://invisible-island.net/ncurses/announce-6.2.html#h3-bug-fixes

Since less (as a termcap application) doesn't use any of the
structs, I don't see how a difference in alignment would affect it.

If (as suggested below) the structs are misaligned, one could add
a step in the build to show the offsets (make check),
for both tinfo and tinfow.

Regarding tarballs - I don't keep the development tarballs indefinitely.
Patches are retained (and accumulated in a zip-file).  The "same"
information is exported to git.
Comment 15 Vadim A. Misbakh-Soloviov (mva) gentoo-dev 2023-07-18 14:25:22 UTC
By the way, less is not the only application that doesn't want to work with `TERM=xterm-direct256`.
Same for `tmux` and `mtr`:

`tmux`:
missing or unsuitable terminal: xterm-direct256

`mtr`:
Error opening terminal: xterm-direct256.

(both exiting with code 1)

Also, vim9 fails to enter alt_screen, and `mc` blames that terminal doesn't support 256colors (despite that xterm-direct256 is exactly for 256color support)
Comment 16 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-07-18 14:51:27 UTC
Okay, so it seems like there really is an issue with newer ncurses and certain terminfos if not using tinfow. No mixing involved.
Comment 17 Thomas Dickey 2023-07-18 21:55:47 UTC
Created attachment 865763 [details]
script used to mock-up the Gentoo packages
Comment 18 Thomas Dickey 2023-07-18 21:59:04 UTC
Created attachment 865764 [details]
ncurses debugging trace from "demo_terminfo"

I created this trace by setting NCURSES_TRACE=0xfffff when running "demo_terminfo" in the mockup for "ncurses", which shows that it
successfully reads the terminal database entry with extended numbers,
which are truncated to 32767.  There's a "demo_termcap" program too,
but it wouldn't see any big numbers.
Comment 19 Thomas Dickey 2023-07-18 22:06:21 UTC
I checked with a mockup of the Gentoo package configuration,
but see no problem running it.  If you've configured with the
trace feature, you may see some useful information with it.

fwiw, both the terminfo and termcap library interfaces work for me.

(The issue with openrc isn't applicable to vim and less,
since they use tgoto rather than tparm).

That's with current code - the changes we discussed earlier for tparm
were after 20230401 (which is the title of this bug report) and before
the 20230527 used in the ebuild.
Comment 20 Thomas Dickey 2023-07-18 22:19:14 UTC
Created attachment 865766 [details]
out from infocmp ABI 5 versus 6

Just as a reminder, "tinfo" does not support the extended number format introduced in ncurses 6.1, which means that (while the terminal description is certainly usable by termcap applications) some of the extended terminfo features are limited.  Here's the output from infocmp, for "xterm-direct256" to illustrate.