diff --git a/libr/core/cbin.c b/libr/core/cbin.c index 7c47fb2b2aca7..1589449431a64 100644 --- a/libr/core/cbin.c +++ b/libr/core/cbin.c @@ -2764,11 +2764,10 @@ static RIODesc *findReusableFile(RIO *io, const char *uri, int perm) { return arg.desc; } -static bool io_create_mem_map(RIO *io, RBinSection *sec, ut64 at) { +static bool io_create_mem_map(RIO *io, RBinSection *sec, ut64 at, ut64 gap) { r_return_val_if_fail (io && sec, false); bool reused = false; - ut64 gap = sec->vsize - sec->size; char *uri = r_str_newf ("null://%"PFMT64u, gap); RIODesc *desc = findReusableFile (io, uri, sec->perm); if (desc) { @@ -2800,6 +2799,9 @@ static bool io_create_mem_map(RIO *io, RBinSection *sec, ut64 at) { return true; } + + + static void add_section(RCore *core, RBinSection *sec, ut64 addr, int fd) { if (!r_io_desc_get (core->io, fd) || UT64_ADD_OVFCHK (sec->size, sec->paddr) || UT64_ADD_OVFCHK (sec->size, addr) || !sec->vsize) { @@ -2807,18 +2809,16 @@ static void add_section(RCore *core, RBinSection *sec, ut64 addr, int fd) { } ut64 size = sec->vsize; + const ut64 fdsize = r_io_fd_size (core->io, fd); + const ut64 psize = (sec->paddr < fdsize)? R_MIN (sec->size, fdsize - sec->paddr): 0LL; // if there is some part of the section that needs to be zeroed by the loader // we add a null map that takes care of it - if (sec->vsize > sec->size) { - if (!io_create_mem_map (core->io, sec, addr + sec->size)) { - return; - } - size = sec->size; - if (!size) { + if (sec->vsize > psize) { + size = psize; + if (!io_create_mem_map (core->io, sec, addr + psize, sec->vsize - psize) || !size) { return; } } - // then we map the part of the section that comes from the physical file char *map_name = r_str_newf ("fmap.%s", sec->name); if (!map_name) { diff --git a/test/db/cmd/cmd_open b/test/db/cmd/cmd_open index 7cb0707815a1d..993722db8e067 100644 --- a/test/db/cmd/cmd_open +++ b/test/db/cmd/cmd_open @@ -69,7 +69,7 @@ oon o EOF EXPECT=<