Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out-of-bounds read #43

Open
evgeni opened this issue Apr 30, 2016 · 2 comments
Open

out-of-bounds read #43

evgeni opened this issue Apr 30, 2016 · 2 comments
Assignees

Comments

@evgeni
Copy link
Contributor

evgeni commented Apr 30, 2016

Original report in Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=776239

Unshield crashes on this (slightly corrupted) archive:

$ unshield t data1.cab
Segmentation fault

GDB says it's an out-of-bounds read:

#0  0xf7fb565a in get_unaligned_le32 (p=0x5f40e4e8 <error: Cannot access memory at address 0x5f40e4e8>) at internal.h:138
#1  0xf7fb5732 in unshield_component_new (header=0x804dfd0, offset=1463549952) at component.c:30
#2  0xf7fb8eff in unshield_header_get_components (header=0x804dfd0) at libunshield.c:155
#3  0xf7fb942d in unshield_read_headers (unshield=0x804dfb0, version=-1) at libunshield.c:309
#4  0xf7fb95db in unshield_open_force_version (filename=0xffffda22 "data1.cab", version=-1) at libunshield.c:361
#5  0x08049db1 in main (argc=3, argv=0xffffd864) at unshield.c:574
@twogood
Copy link
Owner

twogood commented Apr 30, 2016

PR is welcome!

@maqifrnswa
Copy link
Contributor

maqifrnswa commented Jan 9, 2017

triaging: the files are corrupted such that it's giving a huge offset between header components.
#1 0xf7fb5732 in unshield_component_new (header=0x804dfd0, offset=1463549952) at component.c:30

this allows unshield_header_get_buffer in lib/helper.c can return a pointer to memory outside of header. Here's the code

uint8_t* unshield_header_get_buffer(Header* header, uint32_t offset)
{
  if (offset)
    return 
      header->data +
      header->common.cab_descriptor_offset +
      offset;
  else
    return NULL;
}

possible fix, before returning header->data + header->common.cab_descriptor_offset + offset, check that it is within the size of header (header->data + header->common.cab_descriptor_offset + offset is < header->data+header->size, probably need to add 2 or 4 to each of them for 16 or 32 bits as well).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants