Solve the Error “corrupted size vs. prev_size” glibc

C++ is a general-purpose powerful programming language, which is popular to develop games, browsers, operating systems, web applications, and other web programs. The compiler of C++ is user-friendly, and programmers easily compile the codes. When you are working with the language to design a project for the website, you can encounter errors as well. Errors are common no matter what language you use for programming, the same goes for c++. You may get the error warning “corrupted size vs. prev_size” glibc.

Here, in this article, we will guide you on how to solve the error and what measures you need to follow to fix it. But, before that, we will discuss how the error occurs.

How the error pops up

The cause of the error warning is implementing a JNA bridge to FDK-ACC. When you do that, the error shows. Check out the code

#1 0x00007f3e92e00f5d in __GI_abort () at abort.c:90
 #2 0x00007f3e92e4928d in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7f3e92f70528 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:181
 #3 0x00007f3e92e5064a in malloc_printerr (action=<optimized out>, str=0x7f3e92f6cdee "corrupted size vs. prev_size", ptr=<optimized out>, ar_ptr=<optimized out>) at malloc.c:5426
 #4 0x00007f3e92e5304a in _int_free (av=0x7f3de0000020, p=<optimized out>, have_lock=0) at malloc.c:4337
 #5 0x00007f3e92e5744e in __GI___libc_free (mem=<optimized out>) at malloc.c:3145
 #6 0x00007f3e113921e9 in FDKfree (ptr=0x7f3de009df60) at libSYS/src/genericStds.cpp:233
 #7 0x00007f3e1130d7d3 in Free_AacEncoder (p=0x7f3de0115740) at libAACenc/src/aacenc_lib.cpp:407
 #8 0x00007f3e1130fbb3 in aacEncClose (phAacEncoder=0x7f3de0115740) at libAACenc/src/aacenc_lib.cpp:1395
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
  set = {__val = {4, 6378670679680, 645636045657660056, 90523359816, 139904561311072, 292199584, 139903730612120, 139903730611784, 139904561311088, 1460617926600, 47573685816, 4119199860131166208, 
  139904593745464, 139904553224483, 139904561311136, 288245657}}
  pid = <optimized out>
  tid = <optimized out>
 #1 0x00007f3e92e00f5d in __GI_abort () at abort.c:90
  save_stage = 2
  act = {__sigaction_handler = {sa_handler = 0x7f3de026db10, sa_sigaction = 0x7f3de026db10}, sa_mask = {__val = {139903730540556, 19, 30064771092, 812522497172832284, 139903728706672, 1887866374039011357, 
  139900298780168, 3775732748407067896, 763430436865, 35180077121538, 4119199860131166208, 139904561311552, 139904553065676, 1, 139904561311584, 139904561312192}}, sa_flags = 4096, 
  sa_restorer = 0x14}
  sigs = {__val = {32, 0 <repeats 15 times>}}
 #2 0x00007f3e92e4928d in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7f3e92f70528 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/posix/libc_fatal.c:181
  ap = {{gp_offset = 40, fp_offset = 32574, overflow_arg_area = 0x7f3e11adf1d0, reg_save_area = 0x7f3e11adf160}}
  fd = <optimized out>
  list = <optimized out>
  nlist = <optimized out>
  cp = <optimized out>
  written = <optimized out>
 #3 0x00007f3e92e5064a in malloc_printerr (action=<optimized out>, str=0x7f3e92f6cdee "corrupted size vs. prev_size", ptr=<optimized out>, ar_ptr=<optimized out>) at malloc.c:5426
  buf = "00007f3de009e9f0"
  cp = <optimized out>
  ar_ptr = <optimized out>
  ptr = <optimized out>
  str = 0x7f3e92f6cdee "corrupted size vs. prev_size"
  action = <optimized out>
 #4 0x00007f3e92e5304a in _int_free (av=0x7f3de0000020, p=<optimized out>, have_lock=0) at malloc.c:4337
  size = 2720
  fb = <optimized out>
  nextchunk = 0x7f3de009e9f0
  nextsize = 736
  nextinuse = <optimized out>
  prevsize = <optimized out>
  bck = <optimized out>
  fwd = <optimized out>
  errstr = 0x0
  locked = <optimized out>
 #5 0x00007f3e92e5744e in __GI___libc_free (mem=<optimized out>) at malloc.c:3145
  ar_ptr = <optimized out>
  p = <optimized out>
  hook = <optimized out>
 #6 0x00007f3e113921e9 in FDKfree (ptr=0x7f3de009df60) at libSYS/src/genericStds.cpp:233
 No locals.
 #7 0x00007f3e1130d7d3 in Free_AacEncoder (p=0x7f3de0115740) at libAACenc/src/aacenc_lib.cpp:407
 No locals.
 #8 0x00007f3e1130fbb3 in aacEncClose (phAacEncoder=0x7f3de0115740) at libAACenc/src/aacenc_lib.cpp:1395
  hAacEncoder = 0x7f3de009df60
  err = AACENC_OK

How to fix “corrupted size vs. prev_size” glibc

To overcome the error warning, you need to understand the cause.  It happens when structured fields controlled by the memory chunk in the adjacent following chunk are overwritten because of the out-of-bounds access by the code. This is the reason you get the error warning when compiling the code. The different chunk size from the next chunk control structure needs to be checked when you encounter the error.

Quick Solution

The error can be solved by simply disabling the alignment. The Java/JNA layer has been through the structural mapping that advised different #pragma related to alignment/padding from where it used the dll/so to compile. Here, you get the data that caused the error, which is written beyond the structure boundary allocated.

This is the best solution you can do to get the error fixes. You just need to disable the alignment.

Conclusion

We shed light on the solution to fix the “corrupted size vs. prev_size” glibc. The solution is powerful enough to help you remove the error.

I wish you happy coding with no errors!

Reference Source: https://www.anycodings.com/1questions/2082662/understanding-corrupted-size-vs-prevsize-glibc-error

https://stackoverflow.com/questions/49628615/understanding-corrupted-size-vs-prev-size-glibc-error

Leave a Reply

Your email address will not be published. Required fields are marked *