From 8eee85cb9e8d996d324fd54db67043305dcbbc40 Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Sat, 5 Mar 2016 17:39:14 +0100 Subject: [PATCH 1/6] Issue #380 - Experimental patch in issue-380 branch --- src/parser.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/parser.c b/src/parser.c index 4ca544c..2d9de5c 100644 --- a/src/parser.c +++ b/src/parser.c @@ -867,7 +867,8 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) #if !defined(NDEBUG) && defined(_MSC_VER) in_parse_block++; parse_block_cnt++; - SPRTF("Entering ParseBlock %d... %d\n",in_parse_block,parse_block_cnt); + SPRTF("Entering ParseBlock %d... %d %s\n",in_parse_block,parse_block_cnt, + ((element && element->element) ? element->element : "")); #endif if ( element->tag->model & CM_EMPTY ) { @@ -943,14 +944,21 @@ void TY_(ParseBlock)( TidyDocImpl* doc, Node *element, GetTokenMode mode) return; } +#if OBSOLETE /* Issue #380 Kill this code! But leave in src, just in case! */ if ( nodeIsBODY( node ) && DescendantOf( element, TidyTag_HEAD )) { /* If we're in the HEAD, close it before proceeding. This is an extremely rare occurance, but has been observed. + **************************************************************** + Issue #380 - This can cause an INFINITE loop! + This code was added to SF CVS Tidy + revision 1.121 by lpassey, Wed Jul 28 18:08:06 2004 UTC + **************************************************************** */ TY_(UngetToken)( doc ); break; } +#endif /* #if OBSOLETE */ if ( nodeIsHTML(node) || nodeIsHEAD(node) || nodeIsBODY(node) ) { From b83d5ffb03bbea12f442398118053839fa9cc2e0 Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Sat, 5 Mar 2016 17:40:32 +0100 Subject: [PATCH 2/6] Issue #380 - Bump to version 5.1.45-Exp1 --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index e153d99..f57744b 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ -5.1.45 +5.1.45-Exp1 2016.03.04 From 8dda04f1df6a5b43664a55a8c510b3100808f99a Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Sun, 6 Mar 2016 17:31:00 +0100 Subject: [PATCH 3/6] Issue #379 - Care about 'ix' going negative. How this lasted so long in the code is a mystery! But of course it will only be a read out-of-bounds if testing the first character in the lexer, and it is a spacey char. A big thanks to @gaa-cifasis for running ASAN tests on Tidy. --- src/pprint.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pprint.c b/src/pprint.c index bb7eccc..206f234 100644 --- a/src/pprint.c +++ b/src/pprint.c @@ -1034,10 +1034,11 @@ static void PPrintText( TidyDocImpl* doc, uint mode, uint indent, ix = IncrWS( ix, end, indent, ixWS ); } else if (( c == '&' ) && (TY_(HTMLVersion)(doc) == HT50) && - (((ix + 1) == end) || (((ix + 1) < end) && (isspace(doc->lexer->lexbuf[ix+1])))) ) + (((ix + 1) == end) || (((ix + 1) < end) && (isspace(doc->lexer->lexbuf[ix+1] & 0xff)))) ) { /*\ * Issue #207 - This is an unambiguous ampersand need not be 'quoted' in HTML5 + * Issue #379 - Ensure only 0 to 255 passed to 'isspace' to avoid debug assert \*/ PPrintChar( doc, c, (mode | CDATA) ); } @@ -1866,9 +1867,12 @@ static int TextEndsWithNewline(Lexer *lexer, Node *node, uint mode ) if ( (mode & (CDATA|COMMENT)) && TY_(nodeIsText)(node) && node->end > node->start ) { uint ch, ix = node->end - 1; - /* Skip non-newline whitespace. */ - while ( ix >= node->start && (ch = (lexer->lexbuf[ix] & 0xff)) - && ( ch == ' ' || ch == '\t' || ch == '\r' ) ) + /*\ + * Skip non-newline whitespace. + * Issue #379 - Only if ix is GT start can it be decremented! + \*/ + while ( ix > node->start && (ch = (lexer->lexbuf[ix] & 0xff)) + && ( ch == ' ' || ch == '\t' || ch == '\r' ) ) --ix; if ( lexer->lexbuf[ ix ] == '\n' ) From 98f32ddebbe8dd172c15b7d1c82fd7b1c5583ff3 Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Sun, 6 Mar 2016 17:38:48 +0100 Subject: [PATCH 4/6] Issue #379 - Bump to version 5.1.45-Exp2 --- version.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.txt b/version.txt index f57744b..f8533e4 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ -5.1.45-Exp1 -2016.03.04 +5.1.45-Exp2 +2016.03.06 From e6f1533d896eef9cabced6e6946f7749b49b1e85 Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Fri, 18 Mar 2016 18:47:00 +0100 Subject: [PATCH 5/6] Issue #383 - Output message file text byte-by-byte --- src/message.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/message.c b/src/message.c index 2328515..6de12bc 100755 --- a/src/message.c +++ b/src/message.c @@ -260,30 +260,32 @@ static void messagePos( TidyDocImpl* doc, TidyReportLevel level, uint code, if ( go ) { enum { sizeBuf=1024 }; - char *buf = TidyDocAlloc(doc,sizeBuf); + TidyOutputSink *outp = &doc->errout->sink; + char *buf = (char *)TidyDocAlloc(doc,sizeBuf); const char *cp; + byte b; if ( line > 0 && col > 0 ) { ReportPosition(doc, line, col, buf, sizeBuf); -#if !defined(NDEBUG) && defined(_MSC_VER) - SPRTF("%s",buf); -#endif for ( cp = buf; *cp; ++cp ) - TY_(WriteChar)( *cp, doc->errout ); + { + b = (*cp & 0xff); + outp->putByte( outp->sinkData, b ); + } } LevelPrefix( level, buf, sizeBuf ); -#if !defined(NDEBUG) && defined(_MSC_VER) - SPRTF("%s",buf); - SPRTF("%s\n",messageBuf); -#else for ( cp = buf; *cp; ++cp ) - TY_(WriteChar)( *cp, doc->errout ); - + { + b = (*cp & 0xff); + outp->putByte( outp->sinkData, b ); + } for ( cp = messageBuf; *cp; ++cp ) - TY_(WriteChar)( *cp, doc->errout ); + { + b = (*cp & 0xff); + outp->putByte( outp->sinkData, b ); + } TY_(WriteChar)( '\n', doc->errout ); -#endif TidyDocFree(doc, buf); } TidyDocFree(doc, messageBuf); From 06215769aa297bea25fa260a70cfa39e4524fdf7 Mon Sep 17 00:00:00 2001 From: Geoff McLane Date: Fri, 18 Mar 2016 18:48:08 +0100 Subject: [PATCH 6/6] Issue #383 - Bump version 5.1.45-Exp3 --- version.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.txt b/version.txt index f8533e4..90d2523 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ -5.1.45-Exp2 -2016.03.06 +5.1.45-Exp3 +2016.03.18