commit dd642560fb9c88572cae7ac4bbd6c6efb27d7fab
Author: Juergen Spitzmueller <[email protected]>
Date: Sat Aug 23 07:54:00 2025 +0200
Prevent recursive counter relation which makes no sense and crashes (#12544)
---
src/Counters.cpp | 12 +++++++++---
src/Counters.h | 2 +-
src/TextClass.cpp | 2 +-
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/Counters.cpp b/src/Counters.cpp
index 76e0e4ec2d..d8cac2a008 100644
--- a/src/Counters.cpp
+++ b/src/Counters.cpp
@@ -51,7 +51,7 @@ Counter::Counter(docstring const & mc, docstring const & ls,
}
-bool Counter::read(Lexer & lex)
+bool Counter::read(Lexer & lex, docstring const & name)
{
enum {
CT_WITHIN = 1,
@@ -156,6 +156,12 @@ bool Counter::read(Lexer & lex)
else
prettyformat_ = "## (" + guiname_ + ")";
}
+ // Check for recursive relation which would crash (#12544)
+ if (parent_ == name) {
+ LYXERR0("A counter cannot be within itself! "
+ "Ignoring 'Within " << parent_ << "' for
counter " << name);
+ parent_.erase();
+ }
}
// Here if have a full counter if getout == true
@@ -278,12 +284,12 @@ bool Counters::read(Lexer & lex, docstring const & name,
bool makenew)
{
if (hasCounter(name)) {
LYXERR(Debug::TCLASS, "Reading existing counter " <<
to_utf8(name));
- return counterList_[name].read(lex);
+ return counterList_[name].read(lex, name);
}
LYXERR(Debug::TCLASS, "Reading new counter " << to_utf8(name));
Counter cnt;
- bool success = cnt.read(lex);
+ bool success = cnt.read(lex, name);
// if makenew is false, we will just discard what we read
if (success && makenew)
counterList_[name] = cnt;
diff --git a/src/Counters.h b/src/Counters.h
index 5e256cfc2e..73c5817659 100644
--- a/src/Counters.h
+++ b/src/Counters.h
@@ -39,7 +39,7 @@ public:
docstring const & lsa, docstring const & prettyformat,
docstring const & guiname);
/// \return true on success
- bool read(support::Lexer & lex);
+ bool read(support::Lexer & lex, docstring const & name);
///
void set(int v);
///
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index c52d6de019..86df547b43 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -881,7 +881,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc,
ReadType rt)
Counter c;
// Since we couldn't read the name, we
just scan the rest
// and discard it.
- c.read(lexrc);
+ c.read(lexrc, name);
} else
error = !counters_.read(lexrc, name,
!ifcounter);
}
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs