Add the missing loop exit condition based on Z_STREAM_END #286
Add the missing loop exit condition based on Z_STREAM_END #286harukat wants to merge 1 commit intoossc-db:masterfrom
Conversation
…) return. doDeflate() function has no loop exit condition if deflate() returns Z_STREAM_END. Therefore, this code could potentially cause an infinite loop. Similar code using zlib in PostgreSQL has such an exit condition, so it would be desirable to do the same for pg_rman.
|
I don't have prior experience working directly with zlib, so I may be misunderstanding something. Based on my reading of zlib.h, it seems that deflate() returns This suggests that a situation where If we want to explicitly handle this case, I think it would be more appropriate to add an assertion (e.g., Assert( status == Z_STREAM_END) when exiting the loop, following the example style from the official zlib site, rather than introducing a new condition to break the loop. Here is the relevevant snippet from the site: |
|
I understand that this fix is not mandatory.
|
As described earlier, I think deflate() only returns Given that this logic is used during backup, where disk I/O is typically the bottleneck, the cost of this kind of check might not be a real concern in practice. However, it may be better not to have things we don't need. Also, I find it slightly worrying that under some edge cases -- say, if there's a bug in zlib and avail_in is not zero but deflate() exits the loop without an error -- we might end up with unexpected behavior. |
doDeflate() function has no loop exit condition if deflate() returns Z_STREAM_END.
Therefore, this code could potentially cause an infinite loop.
Similar code using zlib in PostgreSQL has such an exit condition, so it would be desirable to do the same for pg_rman.