From 6c7f32a75106b1c6f464b0f04f583590fa574fee Mon Sep 17 00:00:00 2001 From: Jehan Date: Wed, 22 Apr 2020 22:11:51 +0200 Subject: [PATCH] Issue #10: Crashing sequence with nsSJISProber. uchardet_handle_data() should not try to process data of nul length. Still this is not technically an error to feed empty data to the engine, and I could imagine it could happen especially when done in some automatic process with random input files (which looks like what was happening in the reporter case). So feeding empty data just returns a success without actually doing any processing, allowing to continue the data feed. --- src/uchardet.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/uchardet.cpp b/src/uchardet.cpp index f1951d1..46ee257 100644 --- a/src/uchardet.cpp +++ b/src/uchardet.cpp @@ -91,7 +91,11 @@ void uchardet_delete(uchardet_t ud) int uchardet_handle_data(uchardet_t ud, const char * data, size_t len) { - nsresult ret = reinterpret_cast(ud)->HandleData(data, (PRUint32)len); + nsresult ret = NS_OK; + + if (len > 0) + ret = reinterpret_cast(ud)->HandleData(data, (PRUint32)len); + return (ret != NS_OK); }