luaL_loadfile segfault in _IO_file_underflow
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lua5.1 (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned |
Bug Description
This is a bit of a niche bug, that only happens on a particular combination of OS, CPU architecture, and LUA package, and admittedly is a pretty unusual use-case.
The original error report relates to my vlcj bindings for the vlc media player - but I have been able to distil the problem down to a very specific and simple test case.
My test case embeds the execution of a LUA script inside Java code.
I have tested this using the Oracle provided Java6 and Java7 JVMs, and the OpenJDK Java6 and Java7 JVMs. All with the same results. There is no observed problem with LUA outside of a JVM.
My test case works just fine on 64-bit Ubuntu/Kubuntu and Lubuntu.
My unchanged test case fails on 32-bit Ubuntu/Kubuntu and Lubuntu.
The nature of the failure is a fatal JVM crash caused by a segfault triggered by some lua code. This is repeatable 100% of the time.
An example JVM crash dump contains this:
# SIGSEGV (0xb) at pc=0xb767c688, pid=4407, tid=2080172864
#
# JRE version: 7.0_05-b05
# Java VM: Java HotSpot(TM) Server VM (23.1-b03 mixed mode linux-x86 )
# Problematic frame:
# C [libc.so.
The backtrace from gdb contains this:
#0 0x0028f688 in _IO_file_underflow () from /lib/i386-
#1 0x001d83a9 in _IO_default_uflow () from /lib/i386-
#2 0x001d81c0 in __uflow () from /lib/i386-
#3 0x001ce6d2 in getc () from /lib/i386-
#4 0x02c8abc4 in luaL_loadfile () from /usr/lib/
The piece of code that triggers this bug is in lauxlib.c in the luaL_loadfile method:
while ((c = getc(lf.f)) != EOF && c != LUA_SIGNATURE[0]) ; <--- Crash failure triggered here after freopen
This bug is only triggered when the LUA script being opened has been compiled by luac - if I run the same test with a source script rather than a compiled script the fatal crash is not triggered. I think the lua code essentially opens the script file, sniffs for a magic number to check if it is a binary script, and if so reopens the file. I think it is this act of reopening the file that ultimately triggers the bug.
There is a long thread on github with my entire history of investigating this issue: https:/
I am reporting this as an Ubuntu bug rather than a JVM or lua bug because if I remove the lua package provided by Ubuntu and instead build lua myself using the vanilla untouched 5.1 source code from lua.org, my test case does in fact work on 32-bit Ubuntu.
cat /etc/issue
Ubuntu 12.04.2 LTS
uname -a
Linux Ubuntu32 3.2.0-38-generic #61-Ubuntu SMP Tue Feb 19 12:20:02 UTC 2013 i686 i686 i386 GNU/Linux
lsb_release -rd
Description: Ubuntu 12.04.2 LTS
Release: 12.04
apt-cache policy liblua5.1-0-dev
liblua5.1-0-dev:
Installed: 5.1.4-12ubuntu1
Candidate: 5.1.4-12ubuntu1
Version table:
*** 5.1.4-12ubuntu1 0
500 http://
100 /var/lib/
My initial report was not entirely accurate.
If I use a Java6 JVM I do *not* see the problem, even on 32-bit Ubuntu.
So there is some interplay of Java7, LUA and 32-bit Ubuntu that triggers the bug. I guess it is possible that this is a JVM bug, but the fact remains that if I use a vanilla lua build rather than the Ubuntu lua build my problem goes away, even on Java7.