Comments (6)
You don't say what hardware or OS you are on. How many bits are in your size_t? What type did you use for number in your LuaJIT build?
Do you have a minimal program to reproduce the error? Does it only occur on LuaJIT?
Are you interested in working on a patch?
from luaposix.
I will investigate more and answer your questions if needed, but isn't size_t
an unsigned type, or at least cannot be guaranteed to be a signed type ? If so, how could the code in question be correct, checking for a negative value ?
As a reference, here read returns ssize_t
.
from luaposix.
Can confirm that by fixing the "overflow" I could see the actual error underneath: a bad file descriptor error from read()
(which is its own mystery, but orthogonal to this issue).
To reproduce:
local unistd = require "posix.unistd"
local stdio = require "posix.stdio"
local f = io.tmpfile()
local fd = stdio.fileno(f)
f:close()
local str = assert(unistd.read(fd, 4096))
On Arch Linux 64 bits:
luajit: string length overflow
stack traceback:
[C]: in function 'read'
bug.lua:7: in main chunk
[C]: at 0x55e4b41feed0
lua5.3: memory allocation error: block too big
stack traceback:
[C]: in function 'posix.unistd.read'
bug.lua:7: in main chunk
[C]: in ?
Test fix:
index 20e5803..d8b8be7 100644
--- a/ext/posix/unistd.c
+++ b/ext/posix/unistd.c
@@ -930,7 +930,8 @@ static int
Pread(lua_State *L)
{
int fd = checkint(L, 1);
- size_t count = (size_t)checkinteger(L, 2), ret;
+ size_t count = (size_t)checkinteger(L, 2);
+ ssize_t ret;
void *ud, *buf;
lua_Alloc lalloc;
@@ -943,6 +944,7 @@ Pread(lua_State *L)
return pusherror(L, "lalloc");
ret = read(fd, buf, count);
+ if(ret < 0) printf("read => %jd\n", ret);
if (ret >= 0)
lua_pushlstring(L, buf, ret);
lalloc(ud, buf, count, 0);
Result:
read => -1
luajit: bug.lua:7: Bad file descriptor
stack traceback:
[C]: in function 'assert'
bug.lua:7: in main chunk
[C]: at 0x563a6735bed0
from luaposix.
Awesome catch, thanks for reporting and especially for also providing a fix. I expect to be able to integrate your fix the weekend after next (I'm on my phone without a computer until then). If you'd like it to be upstreamed sooner, a PR with your fix, along with a test case that passes GitHub CI to exercise it so we don't accidentally reintroduce the problem in future would be great! I can hit merge from my phone in that case
from luaposix.
The bad descriptor is a symptom of this issue: #217
Different implementations of Lua wrap file objects differently, and until we figure out how to portably wrap a libc descriptor up in a Lua file object, you can't use luaposix files in Lua io calls, and vice versa
from luaposix.
I expect to be able to integrate your fix the weekend after next [...]
Thanks. Even if it's just changing a variable type, I don't want to mess with GitHub and I'm not in a hurry.
The bad descriptor is a symptom of this issue: #217
I encountered that issue, but I'm only using stdio.fileno
, which should be fine.
(In my case, the error was on reading a pipe.)
from luaposix.
Related Issues (20)
- Lua 5.4 support HOT 3
- luke install installs into incorrect location HOT 4
- lseek() return value overflows on large files. HOT 9
- The values returned by spawn() do not match spawn()'s documentation.
- strftime: garbage from %z, garbage and segfaults from %Z HOT 10
- posix.sys.resource: rlim_t values may overflow integers HOT 1
- `readlink` doesnβt work on `/proc/self/fd` magiclinks HOT 1
- Incorrect fork error-handling HOT 2
- luke: fatal: required symbol 'crypt' not found in any of libc, libcrypt HOT 5
- Using unix sockets in a non-blocking manner / timeouts HOT 2
- Small error in doc for poll(): return is not 0/1 but the number of ready fd's
- pwd.getpwuid fails with 0.0 as input HOT 3
- posix.fcntl is a function, not a table. HOT 15
- luxposix 36.0 won't compile properly on CentOS7 - time.h issues HOT 14
- posix.sys.socket - recv() crashes with socket and timeout in v36.1 (v36.0) HOT 6
- Lazy loading of posix.sys.stat fails in both 35.1 and 36.1 HOT 6
- luaposix won't compile in termux HOT 26
- Missing rockspec file in v36.1 HOT 7
- Get an error when trying to cross-compile HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from luaposix.