Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8906767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:44:20+00:00 2026-06-15T02:44:20+00:00

Ok.. I’ve made a system which uses zlib to decompress a string… I think

  • 0

Ok.. I’ve made a system which uses zlib to decompress a string… I think it works, but I have a problem with my base64 converter so I can’t be sure the data is correct… it works for a very small string, i.e. “help” but this string causes the buffer overflow
“eJxjZMAOmHCIM+MQZ8EhzgrEAAKAABA=”

this is the function in question!

#include <zlib.h>
#include <stdlib.h>
#include <string.h>
#include "../../inc/tools/Zunz.h"

using namespace tool;

static const int maxUncompressedSize = 4096;

std::string Zunz::UnZip(std::string const& s)
{
    char *cmprsd;
    char uncompressed[maxUncompressedSize];
    int sizeOfS = sizeof(s);
    cmprsd = (char*) malloc(sizeOfS);
    strcpy(cmprsd, s.c_str());

    // deflate
    // zlib struct
    z_stream defstream;
    defstream.zalloc = Z_NULL;
    defstream.zfree = Z_NULL;
    defstream.opaque = Z_NULL;
    defstream.avail_in = (uInt)strlen(cmprsd)+1; // size of input, string + terminator
    defstream.next_in = (Bytef *)cmprsd; // input char array
    defstream.avail_out = (uInt)sizeof(uncompressed); // size of output
    defstream.next_out = (Bytef *)uncompressed; // output char array

    deflateInit(&defstream, Z_DEFAULT_COMPRESSION);
    deflate(&defstream, Z_FINISH);
    deflateEnd(&defstream);

    return(std::string(uncompressed));
}

This code works fine in debug, but causes a buffer overflow in release.. The only two things I think that could be causing this are either 1. incorrect usage of zlib (I’m very new to it) or 2. ive followed this guide: http://www.devside.net/guides/linux/zlib

here’s the output:

    *** buffer overflow detected ***: ./sfml tests terminated
    ======= Backtrace: =========
    /lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x5c)[0x7f6b81c2182c]
    /lib/x86_64-linux-gnu/libc.so.6(+0x109700)[0x7f6b81c20700]
    ./sfml tests[0x4075d2]
    ./sfml tests[0x406e2a]
    ./sfml tests[0x406865]
    ./sfml tests[0x406339]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7f6b81b3876d]
    ./sfml tests[0x406771]
    ======= Memory map: ========
    00400000-0043a000 r-xp 00000000 08:01 788443                             /home/falconmick/sfml tests/bin/Release/sfml tests
    00639000-0063a000 r--p 00039000 08:01 788443                             /home/falconmick/sfml tests/bin/Release/sfml tests
    0063a000-0063b000 rw-p 0003a000 08:01 788443                             /home/falconmick/sfml tests/bin/Release/sfml tests
    0063b000-0063d000 rw-p 00000000 00:00 0 
    01382000-013a3000 rw-p 00000000 00:00 0                                  [heap]
    7f6b7fe6d000-7f6b7fe72000 r-xp 00000000 08:01 6007                       /usr/lib/x86_64-linux-gnu/libXdmcp.so.6.0.0
    7f6b7fe72000-7f6b80071000 ---p 00005000 08:01 6007                       /usr/lib/x86_64-linux-gnu/libXdmcp.so.6.0.0
    7f6b80071000-7f6b80072000 r--p 00004000 08:01 6007                       /usr/lib/x86_64-linux-gnu/libXdmcp.so.6.0.0
    7f6b80072000-7f6b80073000 rw-p 00005000 08:01 6007                       /usr/lib/x86_64-linux-gnu/libXdmcp.so.6.0.0
    7f6b80073000-7f6b80075000 r-xp 00000000 08:01 5996                       /usr/lib/x86_64-linux-gnu/libXau.so.6.0.0
    7f6b80075000-7f6b80275000 ---p 00002000 08:01 5996                       /usr/lib/x86_64-linux-gnu/libXau.so.6.0.0
    7f6b80275000-7f6b80276000 r--p 00002000 08:01 5996                       /usr/lib/x86_64-linux-gnu/libXau.so.6.0.0
    7f6b80276000-7f6b80277000 rw-p 00003000 08:01 5996                       /usr/lib/x86_64-linux-gnu/libXau.so.6.0.0
    7f6b80277000-7f6b80280000 r-xp 00000000 08:01 6029                       /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0
    7f6b80280000-7f6b8047f000 ---p 00009000 08:01 6029                       /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0
    7f6b8047f000-7f6b80480000 r--p 00008000 08:01 6029                       /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0
    7f6b80480000-7f6b80481000 rw-p 00009000 08:01 6029                       /usr/lib/x86_64-linux-gnu/libXrender.so.1.3.0
    7f6b80481000-7f6b80483000 r-xp 00000000 08:01 921657                     /lib/x86_64-linux-gnu/libdl-2.15.so
    7f6b80483000-7f6b80683000 ---p 00002000 08:01 921657                     /lib/x86_64-linux-gnu/libdl-2.15.so
    7f6b80683000-7f6b80684000 r--p 00002000 08:01 921657                     /lib/x86_64-linux-gnu/libdl-2.15.so
    7f6b80684000-7f6b80685000 rw-p 00003000 08:01 921657                     /lib/x86_64-linux-gnu/libdl-2.15.so
    7f6b80685000-7f6b8068f000 r-xp 00000000 08:01 6180                       /usr/lib/x86_64-linux-gnu/libdrm.so.2.4.0
    7f6b8068f000-7f6b8088f000 ---p 0000a000 08:01 6180                       /usr/lib/x86_64-linux-gnu/libdrm.so.2.4.0
    7f6b8088f000-7f6b80890000 r--p 0000a000 08:01 6180                       /usr/lib/x86_64-linux-gnu/libdrm.so.2.4.0
    7f6b80890000-7f6b80891000 rw-p 0000b000 08:01 6180                       /usr/lib/x86_64-linux-gnu/libdrm.so.2.4.0
    7f6b80891000-7f6b80895000 r-xp 00000000 08:01 6039                       /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1.0.0
    7f6b80895000-7f6b80a95000 ---p 00004000 08:01 6039                       /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1.0.0
    7f6b80a95000-7f6b80a96000 r--p 00004000 08:01 6039                       /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1.0.0
    7f6b80a96000-7f6b80a97000 rw-p 00005000 08:01 6039                       /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1.0.0
    7f6b80a97000-7f6b80ab4000 r-xp 00000000 08:01 6749                       /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0
    7f6b80ab4000-7f6b80cb3000 ---p 0001d000 08:01 6749                       /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0
    7f6b80cb3000-7f6b80cb4000 r--p 0001c000 08:01 6749                       /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0
    7f6b80cb4000-7f6b80cb5000 rw-p 0001d000 08:01 6749                       /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0
    7f6b80cb5000-7f6b80cca000 r-xp 00000000 08:01 6739                       /usr/lib/x86_64-linux-gnu/libxcb-glx.so.0.0.0
    7f6b80cca000-7f6b80ec9000 ---p 00015000 08:01 6739                       /usr/lib/x86_64-linux-gnu/libxcb-glx.so.0.0.0
    7f6b80ec9000-7f6b80ecb000 r--p 00014000 08:01 6739                       /usr/lib/x86_64-linux-gnu/libxcb-glx.so.0.0.0
    7f6b80ecb000-7f6b80ecc000 rw-p 00016000 08:01 6739                       /usr/lib/x86_64-linux-gnu/libxcb-glx.so.0.0.0
    7f6b80ecc000-7f6b80ecd000 r-xp 00000000 08:01 5990                       /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1.0.0
    7f6b80ecd000-7f6b810cc000 ---p 00001000 08:01 5990                       /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1.0.0
    7f6b810cc000-7f6b810cd000 r--p 00000000 08:01 5990                       /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1.0.0
    7f6b810cd000-7f6b810ce000 rw-p 00001000 08:01 5990                       /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1.0.0
    7f6b810ce000-7f6b810d3000 r-xp 00000000 08:01 6011                       /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.0
    7f6b810d3000-7f6b812d2000 ---p 00005000 08:01 6011                       /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.0
    7f6b812d2000-7f6b812d3000 r--p 00004000 08:01 6011                       /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.0
    7f6b812d3000-7f6b812d4000 rw-p 00005000 08:01 6011                       /usr/lib/x86_64-linux-gnu/libXfixes.so.3.1.0
    7f6b812d4000-7f6b812d6000 r-xp 00000000 08:01 6005                       /usr/lib/x86_64-linux-gnu/libXdamage.so.1.1.0
    7f6b812d6000-7f6b814d5000 ---p 00002000 08:01 6005                       /usr/lib/x86_64-linux-gnu/libXdamage.so.1.1.0
    7f6b814d5000-7f6b814d6000 r--p 00001000 08:01 6005                       /usr/lib/x86_64-linux-gnu/libXdamage.so.1.1.0
    7f6b814d6000-7f6b814d7000 rw-p 00002000 08:01 6005                       /usr/lib/x86_64-linux-gnu/libXdamage.so.1.1.0
    7f6b814d7000-7f6b814e7000 r-xp 00000000 08:01 6009                       /usr/lib/x86_64-linux-gnu/libXext.so.6.4.0
    7f6b814e7000-7f6b816e7000 ---p 00010000 08:01 6009                       /usr/lib/x86_64-linux-gnu/libXext.so.6.4.0
    7f6b816e7000-7f6b816e8000 r--p 00010000 08:01 6009                       /usr/lib/x86_64-linux-gnu/libXext.so.6.4.0
    7f6b816e8000-7f6b816e9000 rw-p 00011000 08:01 6009                       /usr/lib/x86_64-linux-gnu/libXext.so.6.4.0
    7f6b816e9000-7f6b8170a000 r-xp 00000000 08:01 6280                       /usr/lib/x86_64-linux-gnu/libglapi.so.0.0.0
    7f6b8170a000-7f6b8190a000 ---p 00021000 08:01 6280                       /usr/lib/x86_64-linux-gnu/libglapi.so.0.0.0
    7f6b8190a000-7f6b8190d000 r--p 00021000 08:01 6280                       /usr/lib/x86_64-linux-gnu/libglapi.so.0.0.0
    7f6b8190d000-7f6b8190e000 rw-p 00024000 08:01 6280                       /usr/lib/x86_64-linux-gnu/libglapi.so.0.0.0
    7f6b8190e000-7f6b8190f000 rw-p 00000000 00:00 0 
    7f6b8190f000-7f6b81916000 r-xp 00000000 08:01 921746                     /lib/x86_64-linux-gnu/librt-2.15.so
    7f6b81916000-7f6b81b15000 ---p 00007000 08:01 921746                     /lib/x86_64-linux-gnu/librt-2.15.so
    7f6b81b15000-7f6b81b16000 r--p 00006000 08:01 921746                     /lib/x86_64-linux-gnu/librt-2.15.so
    7f6b81b16000-7f6b81b17000 rw-p 00007000 08:01 921746                     /lib/x86_64-linux-gnu/librt-2.15.so
    7f6b81b17000-7f6b81ccc000 r-xp 00000000 08:01 921642                     /lib/x86_64-linux-gnu/libc-2.15.so
    7f6b81ccc000-7f6b81ecb000 ---p 001b5000 08:01 921642                     /lib/x86_64-linux-gnu/libc-2.15.so
    7f6b81ecb000-7f6b81ecf000 r--p 001b4000 08:01 921642                     /lib/x86_64-linux-gnu/libc-2.15.so
    7f6b81ecf000-7f6b81ed1000 rw-p 001b8000 08:01 921642                     /lib/x86_64-linux-gnu/libc-2.15.so
    7f6b81ed1000-7f6b81ed6000 rw-p 00000000 00:00 0 
    7f6b81ed6000-7f6b81eeb000 r-xp 00000000 08:01 921667                     /lib/x86_64-linux-gnu/libgcc_s.so.1
    7f6b81eeb000-7f6b820ea000 ---p 00015000 08:01 921667                     /lib/x86_64-linux-gnu/libgcc_s.so.1
    7f6b820ea000-7f6b820eb000 r--p 00014000 08:01 921667                     /lib/x86_64-linux-gnu/libgcc_s.so.1
    7f6b820eb000-7f6b820ec000 rw-p 00015000 08:01 921667                     /lib/x86_64-linux-gnu/libgcc_s.so.1
    7f6b820ec000-7f6b821e7000 r-xp 00000000 08:01 921684                     /lib/x86_64-linux-gnu/libm-2.15.so
    7f6b821e7000-7f6b823e6000 ---p 000fb000 08:01 921684                     /lib/x86_64-linux-gnu/libm-2.15.so
    7f6b823e6000-7f6b823e7000 r--p 000fa000 08:01 921684                     /lib/x86_64-linux-gnu/libm-2.15.so
    7f6b823e7000-7f6b823e8000 rw-p 000fb000 08:01 921684                     /lib/x86_64-linux-gnu/libm-2.15.so
    7f6b823e8000-7f6b824cd000 r-xp 00000000 08:01 6655                       /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
    7f6b824cd000-7f6b826cc000 ---p 000e5000 08:01 6655                       /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
    7f6b826cc000-7f6b826d4000 r--p 000e4000 08:01 6655                       /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
    7f6b826d4000-7f6b826d6000 rw-p 000ec000 08:01 6655                       /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17
    7f6b826d6000-7f6b826eb000 rw-p 00000000 00:00 0 
    7f6b826eb000-7f6b82704000 r-xp 00000000 08:01 1065917                    /usr/local/lib/libz.so.1.2.5
    7f6b82704000-7f6b82903000 ---p 00019000 08:01 1065917                    /usr/local/lib/libz.so.1.2.5
    7f6b82903000-7f6b82904000 r--p 00018000 08:01 1065917                    /usr/local/lib/libz.so.1.2.5
    7f6b82904000-7f6b82905000 rw-p 00019000 08:01 1065917                    /usr/local/lib/libz.so.1.2.5
    7f6b82905000-7f6b82944000 r-xp 00000000 08:01 6426                       /usr/lib/x86_64-linux-gnu/libjpeg.so.8.0.2
    7f6b82944000-7f6b82b44000 ---p 0003f000 08:01 6426                       /usr/lib/x86_64-linux-gnu/libjpeg.so.8.0.2
    7f6b82b44000-7f6b82b45000 r--p 0003f000 08:01 6426                       /usr/lib/x86_64-linux-gnu/libjpeg.so.8.0.2
    7f6b82b45000-7f6b82b46000 rw-p 00040000 08:01 6426                       /usr/lib/x86_64-linux-gnu/libjpeg.so.8.0.2
    7f6b82b46000-7f6b82b56000 rw-p 00000000 00:00 0 
    7f6b82b56000-7f6b82bce000 r-xp 00000000 08:01 5921                       /usr/lib/x86_64-linux-gnu/libGLEW.so.1.8.0
    7f6b82bce000-7f6b82dcd000 ---p 00078000 08:01 5921                       /usr/lib/x86_64-linux-gnu/libGLEW.so.1.8.0
    7f6b82dcd000-7f6b82dd3000 r--p 00077000 08:01 5921                       /usr/lib/x86_64-linux-gnu/libGLEW.so.1.8.0
    7f6b82dd3000-7f6b82dd4000 rw-p 0007d000 08:01 5921                       /usr/lib/x86_64-linux-gnu/libGLEW.so.1.8.0
    7f6b82dd4000-7f6b82dd8000 rw-p 00000000 00:00 0 
    7f6b82dd8000-7f6b82de1000 r-xp 00000000 08:01 6027                       /usr/lib/x86_64-linux-gnu/libXrandr.so.2.2.0
    7f6b82de1000-7f6b82fe0000 ---p 00009000 08:01 6027                       /usr/lib/x86_64-linux-gnu/libXrandr.so.2.2.0
    7f6b82fe0000-7f6b82fe1000 r--p 00008000 08:01 6027                       /usr/lib/x86_64-linux-gnu/libXrandr.so.2.2.0
    7f6b82fe1000-7f6b82fe2000 rw-p 00009000 08:01 6027                       /usr/lib/x86_64-linux-gnu/libXrandr.so.2.2.0
    7f6b82fe2000-7f6b83116000 r-xp 00000000 08:01 5992                       /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0
    7f6b83116000-7f6b83316000 ---p 00134000 08:01 5992                       /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0
    7f6b83316000-7f6b83317000 r--p 00134000 08:01 5992                       /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0
    7f6b83317000-7f6b8331c000 rw-p 00135000 08:01 5992                       /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0
    7f6b8331c000-7f6b8337c000 r-xp 00000000 08:01 264024                     /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0
    7f6b8337c000-7f6b8357c000 ---p 00060000 08:01 264024                     /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0
    7f6b8357c000-7f6b8357e000 r--p 00060000 08:01 264024                     /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0
    7f6b8357e000-7f6b8357f000 rw-p 00062000 08:01 264024                     /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0
    7f6b8357f000-7f6b83580000 rw-p 00000000 00:00 0 
    7f6b83580000-7f6b83598000 r-xp 00000000 08:01 921738                     /lib/x86_64-linux-gnu/libpthread-2.15.so
    7f6b83598000-7f6b83797000 ---p 00018000 08:01 921738                     /lib/x86_64-linux-gnu/libpthread-2.15.so
    7f6b83797000-7f6b83798000 r--p 00017000 08:01 921738                     /lib/x86_64-linux-gnu/libpthread-2.15.so
    7f6b83798000-7f6b83799000 rw-p 00018000 08:01 921738                     /lib/x86_64-linux-gnu/libpthread-2.15.so
    7f6b83799000-7f6b8379d000 rw-p 00000000 00:00 0 
    7f6b8379d000-7f6b837bf000 r-xp 00000000 08:01 921620                     /lib/x86_64-linux-gnu/ld-2.15.so
    7f6b8399d000-7f6b839aa000 rw-p 00000000 00:00 0 
    7f6b839bc000-7f6b839bf000 rw-p 00000000 00:00 0 
    7f6b839bf000-7f6b839c0000 r--p 00022000 08:01 921620                     /lib/x86_64-linux-gnu/ld-2.15.so
    7f6b839c0000-7f6b839c2000 rw-p 00023000 08:01 921620                     /lib/x86_64-linux-gnu/ld-2.15.so
    7fff110d9000-7fff110fa000 rw-p 00000000 00:00 0                          [stack]
    7fff1110e000-7fff1110f000 r-xp 00000000 00:00 0                          [vdso]
    ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
    Aborted (core dumped)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:44:22+00:00Added an answer on June 15, 2026 at 2:44 am

    The problem is that by using sizeof(s) you are getting the size of class std::string instead of the string you need to input. Try replacing this:

    int sizeOfS = sizeof(s);
    

    for this:

    int sizeOfS = s.length() + 1;
    

    The “+ 1” is for the null terminator, which is automatically appended to c_str().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I have an autohotkey script which looks up a word in a bilingual dictionary
This could be a duplicate question, but I have no idea what search terms
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have been unable to fix a problem with Java Unicode and encoding. The
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.