diff --git a/src/mod_magnet.c b/src/mod_magnet.c
index 4fd0795..51efb28 100644
|
a
|
b
|
|
| 580 | 580 | if (lua_isnumber(L, -2)) { |
| 581 | 581 | len = lua_tonumber(L, -2); |
| 582 | 582 | } else { |
| 583 | | len = sce->st.st_size; |
| | 583 | len = sce->st.st_size - off; |
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | if (off < 0) { |
| 587 | 587 | return luaL_error(L, "offset for '%s' is negative", fn->ptr); |
| 588 | 588 | } |
| 589 | 589 | |
| 590 | | if (len < off) { |
| 591 | | return luaL_error(L, "offset > length for '%s'", fn->ptr); |
| | 590 | if (len < 0) { |
| | 591 | return luaL_error(L, "length for '%s' is negative", fn->ptr); |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | | chunkqueue_append_file(con->write_queue, fn, off, len - off); |
| | 594 | if (sce->st.st_size < off + len) { |
| | 595 | return luaL_error(L, "file too small; length + offset > filesize for '%s'", fn->ptr); |
| | 596 | } |
| | 597 | |
| | 598 | if (len != 0) { |
| | 599 | chunkqueue_append_file(con->write_queue, fn, off, len); |
| | 600 | } |
| 595 | 601 | } |
| 596 | 602 | |
| 597 | 603 | buffer_free(fn); |