mirror of
				https://github.com/libssh2/libssh2.git
				synced 2025-11-03 22:13:11 +03:00 
			
		
		
		
	Fix zlib deflate usage
Deflate may return Z_OK even when not all data has been compressed if the output buffer becomes full. In practice this is very unlikely to happen because the output buffer size is always some KBs larger than the size of the data passed for compression from the upper layers and I think that zlib never expands the data so much, even on the worst cases. Anyway, this patch plays on the safe side checking that the output buffer is not exhausted. Signed-off-by: Salvador <sfandino@yahoo.com>
This commit is contained in:
		
				
					committed by
					
						
						Daniel Stenberg
					
				
			
			
				
	
			
			
			
						parent
						
							94077f7a58
						
					
				
				
					commit
					c2329aa09e
				
			
							
								
								
									
										13
									
								
								src/comp.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/comp.c
									
									
									
									
									
								
							@@ -198,17 +198,16 @@ comp_method_zlib_comp(LIBSSH2_SESSION *session,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    status = deflate(strm, Z_PARTIAL_FLUSH);
 | 
					    status = deflate(strm, Z_PARTIAL_FLUSH);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (status != Z_OK) {
 | 
					    if ((status == Z_OK) && (strm->avail_out > 0)) {
 | 
				
			||||||
        _libssh2_debug(session, LIBSSH2_TRACE_TRANS,
 | 
					 | 
				
			||||||
                       "unhandled zlib compression error %d", status);
 | 
					 | 
				
			||||||
        return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
 | 
					 | 
				
			||||||
                              "compression failure");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        *dest_len = out_maxlen - strm->avail_out;
 | 
					        *dest_len = out_maxlen - strm->avail_out;
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    _libssh2_debug(session, LIBSSH2_TRACE_TRANS,
 | 
				
			||||||
 | 
					                   "unhandled zlib compression error %d, avail_out", status, strm->avail_out);
 | 
				
			||||||
 | 
					    return _libssh2_error(session, LIBSSH2_ERROR_ZLIB, "compression failure");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * libssh2_comp_method_zlib_decomp
 | 
					 * libssh2_comp_method_zlib_decomp
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user