techee left a comment (geany/geany#4303)

I ended up with something like this:
```diff
diff --git a/ctags/main/parse.c b/ctags/main/parse.c
index b0599b95f..3193110c0 100644
--- a/ctags/main/parse.c
+++ b/ctags/main/parse.c
@@ -4230,7 +4230,7 @@ extern bool runParserInArea (const langType language,
                                                         unsigned long 
sourceLineOffset,
                                                         int promise)
 {
-       bool tagFileResized;
+       bool tagFileResized = false;
 
        verbose ("runParserInArea: %s; "
                         "file: %s, "
@@ -4242,13 +4242,15 @@ extern bool runParserInArea (const langType language,
                         startLine, startCharOffset, sourceLineOffset,
                         endLine, endCharOffset);
 
-       pushArea (doesParserRequireMemoryStream (language),
+       if (pushArea (doesParserRequireMemoryStream (language),
                          startLine, startCharOffset,
                          endLine, endCharOffset,
                          sourceLineOffset,
-                         promise);
-       tagFileResized = createTagsWithFallback1 (language, NULL);
-       popArea  ();
+                         promise))
+       {
+               tagFileResized = createTagsWithFallback1 (language, NULL);
+               popArea  ();
+       }
        return tagFileResized;
 
 }
diff --git a/ctags/main/read.c b/ctags/main/read.c
index 8a305438d..0c20a37d8 100644
--- a/ctags/main/read.c
+++ b/ctags/main/read.c
@@ -1400,7 +1400,7 @@ extern char *readLineFromBypass (
        return data.result;
 }
 
-extern void   pushArea (
+extern bool   pushArea (
                                       bool useMemoryStreamInput,
                                       unsigned long startLine, long 
startColumn,
                                       unsigned long endLine, long endColumn,
@@ -1421,7 +1421,7 @@ extern void   pushArea (
                {
                        File.thinDepth++;
                        verbose ("push thin area (%d)\n", File.thinDepth);
-                       return;
+                       return true;
                }
                error(WARNING, "INTERNAL ERROR: though pushing MEMORY based 
thin area, "
                          "underlying area is a FILE base: %s@%s",
@@ -1454,6 +1454,9 @@ extern void   pushArea (
 
        mio_setpos (File.mio, &original);
 
+       if (q <= p)
+               return false;
+
        invalidatePatternCache();
 
        size_t size = q - p;
@@ -1479,6 +1482,8 @@ extern void   pushArea (
 
        File.input.lineNumberOrigin = ((startLine == 0)? 0: startLine - 1);
        File.source.lineNumberOrigin = ((sourceLineOffset == 0)? 0: 
sourceLineOffset - 1);
+
+       return true;
 }
 
 extern bool isAreaStacked (void)
diff --git a/ctags/main/read_p.h b/ctags/main/read_p.h
index bc67345af..45cd8002d 100644
--- a/ctags/main/read_p.h
+++ b/ctags/main/read_p.h
@@ -83,7 +83,7 @@ extern char *readLineFromBypass (vString *const vLine, MIOPos 
location, long *co
  * args (endColumn): [absolute]
  * args (sourceLineOffset): [buggy]
  */
-extern void   pushArea (
+extern bool   pushArea (
                                       bool useMemoryStreamInput,
                                       unsigned long startLine, long 
startColumn,
                                       unsigned long endLine, long endColumn,
```

I think it's best to check if `pushArea()` succeeds and if not, skip creation 
of subMIO and the run of the subparser completely. When I originally tried to 
create a subMIO to the end of the file with the `-1` parameter and tried to 
parse the PHP file as a HTML file, I ended up with an infinite loop between PHP 
and HTML where subparsers were calling each other.

Should I open a PR against uctags so we get some initial discussion regarding 
this issue? I also have a few MIO updates. This patch doesn't solve the wrong 
offset calculation which should be solved separately (and maybe it's not even 
so critical for the Geany release) but fixes the crash and makes sure that if 
parsers miscalculate offsets somehow, it won't make ctags crash.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/4303#issuecomment-2930758684
You are receiving this because you are subscribed to this thread.

Message ID: <geany/geany/pull/4303/[email protected]>

Reply via email to