out_es: check if converted_size is 0 to prevent SIGFPE(#3905)
We updated re-allocation logic(#3788).
It tries to divide by converted_size.
If converted_size is 0, it causes SIGFPE and exit code 136.
@@ -78,12 +78,18 @@ int es_bulk_append(struct es_bulk *bulk, char *index, int i_len,
* 1. rest of msgpack data size
* 2. ratio from bulk json size and processed msgpack size.
*/
+ if (converted_size == 0) {
+ /* converted_size = 0 causes div/0 */
+ flb_debug("[out_es] converted_size is 0");
+ append_size = ES_BULK_CHUNK;
+ } else {
append_size = (whole_size - converted_size) /* rest of size to convert */
* (bulk->size / converted_size); /* = json size / msgpack size */
if (append_size < ES_BULK_CHUNK) {
/* append at least ES_BULK_CHUNK size */
append_size = ES_BULK_CHUNK;
}
+ }
ptr = flb_realloc(bulk->ptr, bulk->size + append_size);
if (!ptr) {
flb_errno();
