Ticket #1483: mod_magnet_length.patch

File mod_magnet_length.patch, 1.0 kB (added by stbuehler, 6 months ago)
  • src/mod_magnet.c

    diff --git a/src/mod_magnet.c b/src/mod_magnet.c
    index 4fd0795..51efb28 100644
    a b  
    580580                                                if (lua_isnumber(L, -2)) { 
    581581                                                        len = lua_tonumber(L, -2); 
    582582                                                } else { 
    583                                                         len = sce->st.st_size; 
     583                                                        len = sce->st.st_size - off; 
    584584                                                } 
    585585 
    586586                                                if (off < 0) { 
    587587                                                        return luaL_error(L, "offset for '%s' is negative", fn->ptr); 
    588588                                                } 
    589589 
    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); 
    592592                                                } 
    593593 
    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                                                } 
    595601                                        } 
    596602 
    597603                                        buffer_free(fn);