danigargu/heap-viewer

ptmalloc malloc_chunk size may be wrong

EmmaJaneBonestell opened this issue · 0 comments

I may just be overlooking something, but I note that in the misc.py "add_malloc_chunk_struct" function, the struct size is declared as 56 bytes.

125: struct_size = 7*ptr_size

This struct only has six member, and on 64bit platforms, each of the structs in 8 bytes, so aasuming there is no odd struct padding/packing, shouldn't it only be 48 bytes? E.g.

struct_size = 6*ptr_size

A small C test program will also print the struct size out as 48.

#include <stdio.h>

int main() {

struct malloc_chunk;
typedef struct malloc_chunk* mchunkptr;

#define INTERNAL_SIZE_T size_t

struct malloc_chunk {

    INTERNAL_SIZE_T      mchunk_prev_size;  /* Size of previous chunk (if free).  */
    INTERNAL_SIZE_T      mchunk_size;       /* Size in bytes, including overhead. */

    struct malloc_chunk* fd;         /* double links -- used only if free. */
    struct malloc_chunk* bk;

    /* Only used for large blocks: pointer to next larger size.  */
    struct malloc_chunk* fd_nextsize; /* double links -- used only if free. */
    struct malloc_chunk* bk_nextsize;
};

  struct malloc_chunk getsize;

  printf("The size of the malloc_chunk struct is: %lu \n", sizeof(getsize));

}