In Zlib function zlibBufferSync :
it tries to handle a given buffer
the default chunkSize is 16384
** it calls zlib method _processChunk
in Zlib method _processChunk there is a do-while loop calling binding.writeSync method to process the given buffer (parameter named chunk)
the chunkSize options is used as available out memory
the do-while loop calls a function callback that is supposed to handle the case where the available out memory is not enough
the do-while loop breaks if there is an error in the writeSync process
in Zlib method writeSync in calls inflate method and check returned status
if the status is not OK, it marks an error, making the do-while loop breaks
in inflate method:
in case MATCH: if there is no memory left, it breaks the for-loop
ret is Z_OK
** condition flush === Z_FINISH and ret === Z_OK is turning ret to Z_BUF_ERROR
As a consequence :
status to Z_BUF_ERROR marks an error
the do-while loop breaks
the do-while loop does not handle the case where given buffer size is larger than chunk size option
Issue
In Zlib function
zlibBufferSync
: it tries to handle a given buffer the default chunkSize is 16384 ** it calls zlib method_processChunk
in Zlib method
_processChunk
there is a do-while loop callingbinding.writeSync
method to process the given buffer (parameter namedchunk
) the chunkSize options is used as available out memory the do-while loop calls a functioncallback
that is supposed to handle the case where the available out memory is not enough the do-while loop breaks if there is an error in the writeSync processin Zlib method
writeSync
in callsinflate
method and check returned status if the status is not OK, it marks an error, making the do-while loop breaksin
inflate
method: in caseMATCH
: if there is no memory left, it breaks the for-loopret
is Z_OK ** condition flush === Z_FINISH and ret === Z_OK is turning ret to Z_BUF_ERRORAs a consequence :
Proposal
From: https://github.com/browserify/browserify-zlib/blob/master/src/binding.js#L241
_processChunk
can continue to handle large buffer