title: LodePNG crashes when encoding PNG files with size greater than 15000 * 15000 pixels
body: <p>I've been using LodePNG's <code>lodepng_encode24_file</code> to encode some 24-bit RGB image files, and it has worked wonderfully so far. However, I noticed that it appears to crash when I feed it a dataset larger than 15360*15360 pixels in size (14336*14336 pixel images get encoded fine).</p>
  
  <p>A minimal example of this behavior for the 32-bit case (where the maximum size before crashing is slightly lower) can be obtained by simply replacing the line</p>
  
  <pre><code>  unsigned width = 512, height = 512;
  </code></pre>
  
  <p>with</p>
  
  <pre><code>  unsigned width = 1024*14, height = 1024*14;
  </code></pre>
  
  <p>in <a href="https://raw.githubusercontent.com/lvandeve/lodepng/master/example_encode.c" rel="nofollow noreferrer">LodePNG's example_encode.c file</a>, and executing it.</p>
  
  <p>I previously had issues with C code crashing because I was allocating large arrays to stack memory (whose maximum size is generally somewhere around 2MB) instead of heap memory, so as a new user of C, my first instinct was to see if there is an upper limit on heap memory size. </p>
  
  <p>However, <a href="https://stackoverflow.com/a/12687474/3051203">according to this answer</a>, there is no limit on heap memory, so something else must be going wrong.</p>
  
  <p>My second guess was that the crash was due to an inherent limitation on the maximum image dimensions supported by the PNG format itself. However, <a href="https://stackoverflow.com/a/4109505/3051203">according to this answer</a> and the comment below it, the maximum file size supported by PNG is on the order of 4,000,000,000 * 4,000,000,000 pixels, so this is also not the culprit.</p>
  
  <p>Does anyone have a guess as to what might be going wrong? Is anyone else able to reproduce this error when they try it?</p>
  
  <p><strong>EDIT</strong>: As far as RAM consumption is concerned, I have 8GB RAM, and subtracting the hardware-reserved, in-use, modified and standby memory (terms used by Windows Resource Monitor utility) I have about 4GB RAM free when doing the computation. For a 32-bit image of 15000*15000 size, less than 1GB would be needed. Likewise, when I successfully encode 14000*14000 24-bit images, my free RAM never drops below 3GB at any point of the encoding process, so I don't think RAM running out is the problem.</p>