From f59b04565ade4ecfefccafb2bb1d2c669ac44700 Mon Sep 17 00:00:00 2001 From: shenleban tongying Date: Tue, 12 Nov 2024 16:32:32 -0500 Subject: [PATCH] fix: dict.org crashes by incomplete response and str out of bound access --- src/dict/dictserver.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/dict/dictserver.cc b/src/dict/dictserver.cc index ef1e9bcf..018d9339 100644 --- a/src/dict/dictserver.cc +++ b/src/dict/dictserver.cc @@ -538,14 +538,22 @@ void DictServerWordSearchRequest::readMatchData( QByteArray & reply ) if ( word.endsWith( '\"' ) ) { word.chop( 1 ); } - if ( word[ 0 ] == '\"' ) { + if ( word.startsWith( '\"' ) ) { word = word.mid( 1 ); } - this->addMatchedWord( word ); + if ( !word.isEmpty() ) { + this->addMatchedWord( word ); + } } - reply = this->dictImpl->socket.readLine(); + constexpr int halfSecond = 500; + if ( this->dictImpl->socket.waitForReadyRead( halfSecond ) ) { + reply = this->dictImpl->socket.readLine(); + } + else { + return; + } } while ( true ); }