Bug 167633 - LibreOffice debug build crashed on launch when a Java installation with a non-ASCII path is set during configure(rtl_uString_newFromAscii(rtl_uString**, const char*): Assertion `static_cast<unsig ned char>(*pCharStr) < 0x80' failed.)
Summary: LibreOffice debug build crashed on launch when a Java installation with a non...
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Buo-ren Lin (OSSII)
URL:
Whiteboard: target:26.2.0
Keywords:
Depends on:
Blocks:
 
Reported: 2025-07-22 10:10 UTC by 林博仁 Buo-ren Lin
Modified: 2025-08-05 02:39 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description 林博仁 Buo-ren Lin 2025-07-22 10:10:57 UTC
Description:
Encountered this crash on my development host, where I have a JDK installation at ~/應用軟體/jdk24 (應用軟體 stands for "Applications").

This crash isn't produced on a release build, nor is it reproduced when I set --with-jdk-home to /usr/lib/jvm, so the path seems to be hardcoded during build configuration.

After attaching it to a debugger:

```text
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007ffff784527e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007ffff78288ff in __GI_abort () at ./stdlib/abort.c:79
#5  0x00007ffff782881b in __assert_fail_base (fmt=0x7ffff79d01e8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=assertion@entry=0x7ffff7cefee8 "static_cast<unsigned char>(*pCharStr) < 0x80", 
    file=file@entry=0x7ffff7cefcf0 "/libo-core/sal/rtl/ustring.cxx", line=line@entry=243, 
    function=function@entry=0x7ffff7cefe50 "void rtl_uString_newFromAscii(rtl_uString**, const char*)")
    at ./assert/assert.c:96
#6  0x00007ffff783b517 in __assert_fail (assertion=0x7ffff7cefee8 "static_cast<unsigned char>(*pCharStr) < 0x80", 
    file=0x7ffff7cefcf0 "/libo-core/sal/rtl/ustring.cxx", line=243, 
    function=0x7ffff7cefe50 "void rtl_uString_newFromAscii(rtl_uString**, const char*)") at ./assert/assert.c:105
#7  0x00007ffff7c66de4 in rtl_uString_newFromAscii (ppThis=0x7fffffffbef8, 
    pCharStr=0x7fffffffbf8c "應用軟體/jdk-24/lib/amd64/client:/home/brlin/應用軟體/jdk-24/lib/amd64/server:/home/brlin/應用軟體/jdk-24/lib/amd64/native_threads:/home/brlin/應用軟體/jdk-24/lib/amd64")
    at /libo-core/sal/rtl/ustring.cxx:243
#8  0x000055555555d71d in extend_library_path (
    new_element=0x7fffffffbf80 "/home/brlin/應用軟體/jdk-24/lib/amd64/client:/home/brlin/應用軟體/jdk-24/lib/amd64/server:/home/brlin/應用軟體/jdk-24/lib/amd64/native_threads:/home/brlin/應用軟體/jdk-24/lib/amd64") at /libo-core/desktop/unx/source/start.c:590
#9  0x000055555555dbd5 in exec_javaldx (args=0x5555555aeb80) at /libo-core/desktop/unx/source/start.c:701
#10 0x000055555555e070 in sal_main_with_args (argc=1, argv=0x7fffffffd2c8)
    at /libo-core/desktop/unx/source/start.c:829
#11 0x000055555555dd2c in main (argc=1, argv=0x7fffffffd2c8) at /libo-core/desktop/unx/source/start.c:744
```

, I can pinpoint the exact function call that triggered the crash:

```c++
// desktop/unx/source/start.c
static void extend_library_path(const char *new_element)
{
    rtl_uString *pEnvName=NULL, *pOrigEnvVar=NULL, *pNewEnvVar=NULL;

    rtl_uString_newFromAscii(&pEnvName, "LD_LIBRARY_PATH");
    rtl_uString_newFromAscii(&pNewEnvVar, new_element); // <- this one

    ...stripped...
}
```

It appears that the one who designs the logic wrongly assumes that the LD_LIBRARY_PATH environment variable can only contain ASCII characters.

A patch has been made, stay tuned.

Steps to Reproduce:
1. Install a JDK under a non-ASCII path(e.g. ~/軟體/jdk-24).
2. Set JAVA_HOME and PATH environment variables to point to the JDK installation ("~/軟體/jdk-24", and "~/軟體/jdk-24/bin").
3. Build LibreOffice with the `--with-dbgutil` configure option.
4. Run the `./instdir/program/soffice --writer` or `./instdir/program/oosplash` command (./instdir/program/soffice.bin and ./instdir/program/soffice --backtrace will _not_ work).

Actual Results:
No crash.

Expected Results:
The program aborted with the following error message:

```text
$ ./instdir/program/soffice
oosplash: /libo-core/sal/rtl/ustring.cxx:243: void rtl_uString_newFromAscii(rtl_uString**, const char*): Assertion `static_cast<unsigned char>(*pCharStr) < 0x80' failed.
Aborted (core dumped)
```


Reproducible: Always


User Profile Reset: Yes

Additional Info:
Version: 26.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 6381d366672234d899eeff278870cfb1c5d100e9
CPU threads: 16; OS: Linux 6.11; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 1 Mike Kaganski 2025-07-22 10:40:00 UTC
I already checked how can we change Java's path handling. And you know what: we can't. It's the problem with Java: https://bugs.openjdk.org/browse/JDK-4488646 ; and while it's there for ages, it's not going to be fixed, it seems.

So even if we change *our* code to allow non-ASCII paths for Java, we won't be able to pass such strings to its libraries for initialization. So I'm inclined to close NOTOURBUG (even though the crash / assertion is of course in our code).
Comment 2 Buo-ren Lin (OSSII) 2025-07-22 11:07:12 UTC
(In reply to Mike Kaganski from comment #1)
> I already checked how can we change Java's path handling. And you know what:
> we can't. It's the problem with Java:
> https://bugs.openjdk.org/browse/JDK-4488646 ; and while it's there for ages,
> it's not going to be fixed, it seems.
> 
> So even if we change *our* code to allow non-ASCII paths for Java, we won't
> be able to pass such strings to its libraries for initialization. So I'm
> inclined to close NOTOURBUG (even though the crash / assertion is of course
> in our code).

Thanks for your analysis and feedback!  I won't mind much if the bug isn't fixed(it isn't produced in the user side anyway, though "the use of ASCII consumer to consume non-ASCII content" bit still irks me) as long as:

* A bug is created. (DONE)
* The problem is documented somewhere in the development wiki pages.
Comment 3 Buo-ren Lin (OSSII) 2025-07-22 11:24:55 UTC
This bug will affect developers' ability to produce runnable debug builds in such environments(without resorting to workarounds like unsetting the JAVA_HOME environment variable every time one makes such builds or moving their JDK installations).

On second thought, I still would prefer the crash to be "fixed" even when the Java initialization is still broken with its existence.
Comment 4 Stephan Bergmann 2025-07-22 14:14:49 UTC
(In reply to Mike Kaganski from comment #1)
> So even if we change *our* code to allow non-ASCII paths for Java

still, indeed it's a bit silly that while `extend_library_path` in `desktop/unx/source/start.c` is passed a plain 8-bit `const char *new_element`, it nevertheless internally uses UTF-16/`OUString`-based `osl_getEnvironment`/`osl_setEnvironment`
Comment 5 Mike Kaganski 2025-07-22 14:26:09 UTC
(In reply to Stephan Bergmann from comment #4)

You know, I could confuse this with something else - namely, related to Windows. So likely, comment 1 is nonsense and off-topic.
Comment 6 林博仁 Buo-ren Lin 2025-07-22 14:35:10 UTC
I've submitted a patch:

https://gerrit.libreoffice.org/c/core/+/188155

Please review.

Hopefully, this will make my life suffer less(I probably spent half my work day + 3 laptops' CPU time dealing with this issue) and result in more libo patches/tests :)
Comment 7 Commit Notification 2025-07-22 15:21:05 UTC
Buo-ren Lin (OSSII) committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/f16cc7d9a8f987c512d51c62e067c032e619b746

tdf#167633 desktop: Fix dbg build crash in extend_library_path

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 8 林博仁 Buo-ren Lin 2025-07-23 02:32:10 UTC
(In reply to Commit Notification from comment #7)
> The patch should be included in the daily builds available at
> https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
> information about daily builds can be found at:
> https://wiki.documentfoundation.org/Testing_Daily_Builds
> 
> Affected users are encouraged to test the fix and report feedback.

As the daily build won't have non-ASCII characters in its environment it won't be able to be use for reproduction.

I can verify the bug is no longer reproducible in the ebb4f072 revision.