cosmopolitan icon indicating copy to clipboard operation
cosmopolitan copied to clipboard

Bug: Lua fails a `seek`-related test

Open michaellenaghan opened this issue 1 year ago • 0 comments

What happened?

Build lua, and run lua tests:

$ build/bootstrap/make MODE=aarch64 o/aarch64/third_party/lua/lua
$ cd third_party/lua/test/
$ ape ../../../o/aarch64/third_party/lua/lua all.lua

A test in files.lua fails:

***** FILE 'files.lua'*****
testing i/o
../../../o/aarch64/third_party/lua/lua: files.lua:84: assertion failed!
stack traceback:
[C]: in function 'assert'
files.lua:84: in main chunk
(...tail calls...)
all.lua:195: in main chunk
[C]: in ?
.>>> closing state <<<

The failure is happening here:

https://github.com/jart/cosmopolitan/blob/f9dd5683a4de7e7c69fa54fe85a01a935ab3865b/third_party/lua/test/files.lua#L82-L85

Lua expect a seek to offset 1,000 on stdin to fail — but it succeeds (and returns the new offset).

Under the hood, the failing call is here:

https://github.com/jart/cosmopolitan/blob/8e3b361aeba12c47030011bac45badf93eadf611/third_party/lua/liolib.c#L720

l_fseek is a #define, most likely set to fseeko:

https://github.com/jart/cosmopolitan/blob/8e3b361aeba12c47030011bac45badf93eadf611/third_party/lua/liolib.c#L136

What makes this bug interesting is that it may be a Cosmo bug rather than a Cosmo Lua bug.

P.S. I should add that I didn't look at Lua's f_seek code closely; it's still possible that it's a Cosmo Lua bug rather than a Cosmo bug!

Version

Cosmopolitan v3.4.0

What operating system are you seeing the problem on?

Mac

Relevant log output

Please see "What happened?" above.

michaellenaghan avatar Jun 16 '24 16:06 michaellenaghan