This is an automated email from the ASF dual-hosted git repository.
gfphoenix78 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git
The following commit(s) were added to refs/heads/main by this push:
new c9dc773b2a7 Fix PAX CException stack overflow by pass-by-reference and
shrinking buffer
c9dc773b2a7 is described below
commit c9dc773b2a76188fd399e358b323c7c042354164
Author: liushengsong <[email protected]>
AuthorDate: Wed Apr 15 11:42:09 2026 +0800
Fix PAX CException stack overflow by pass-by-reference and shrinking buffer
CException is ~255KB due to stack_[DEFAULT_STACK_MAX_SIZE]. When
Raise(CException ex, ...) passes by value, two copies (510KB) are
placed on the stack, causing stack overflow in backtrace() -> dlopen().
Fix:
- Change Raise/ReRaise to pass CException by reference instead of value
- Reduce DEFAULT_STACK_MAX_SIZE to 1/4 (255KB -> 63KB)
- Callers now construct a local CException and pass it by reference
---
contrib/pax_storage/src/cpp/exceptions/CException.cc | 13 ++++++++-----
contrib/pax_storage/src/cpp/exceptions/CException.h | 7 ++++---
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/contrib/pax_storage/src/cpp/exceptions/CException.cc
b/contrib/pax_storage/src/cpp/exceptions/CException.cc
index 89c572ac0e6..f4ef55bd7c6 100644
--- a/contrib/pax_storage/src/cpp/exceptions/CException.cc
+++ b/contrib/pax_storage/src/cpp/exceptions/CException.cc
@@ -206,7 +206,7 @@ void ErrorMessage::AppendV(const char *format, va_list ap)
noexcept {
const char *ErrorMessage::Message() const noexcept { return &message_[0]; }
int ErrorMessage::Length() const noexcept { return index_; }
-void CException::Raise(CException ex, bool reraise) {
+void CException::Raise(CException &ex, bool reraise) {
#ifdef __GNUC__
if (!reraise) {
StackTrace(&ex.stack_[0]);
@@ -258,20 +258,23 @@ void CException::AppendDetailMessage(const std::string
&message) {
const char *CException::Stack() const { return stack_; }
void CException::Raise(const char *filename, int lineno, ExType extype) {
- Raise(CException(filename, lineno, extype, ""), false);
+ CException ex(filename, lineno, extype, "");
+ Raise(ex, false);
}
void CException::Raise(const char *filename, int lineno, ExType extype,
const char *message) {
- Raise(CException(filename, lineno, extype, message), false);
+ CException ex(filename, lineno, extype, message);
+ Raise(ex, false);
}
void CException::Raise(const char *filename, int lineno, ExType extype,
const std::string &message) {
- Raise(CException(filename, lineno, extype, message.c_str()), false);
+ CException ex(filename, lineno, extype, message.c_str());
+ Raise(ex, false);
}
-void CException::ReRaise(CException ex) { Raise(ex, true); }
+void CException::ReRaise(CException &ex) { Raise(ex, true); }
static const char *exception_names[] = {
"Invalid ExType",
diff --git a/contrib/pax_storage/src/cpp/exceptions/CException.h
b/contrib/pax_storage/src/cpp/exceptions/CException.h
index b3cbed2ab39..28358e3ecb4 100644
--- a/contrib/pax_storage/src/cpp/exceptions/CException.h
+++ b/contrib/pax_storage/src/cpp/exceptions/CException.h
@@ -107,8 +107,9 @@
namespace cbdb {
#define DEFAULT_STACK_MAX_DEPTH 63
+/* 255KB is too large to cause stack overflow, 63KB maybe enough */
#define DEFAULT_STACK_MAX_SIZE \
- ((DEFAULT_STACK_MAX_DEPTH + 1) * PIPE_MAX_PAYLOAD)
+ ((DEFAULT_STACK_MAX_DEPTH + 1) * PIPE_MAX_PAYLOAD / 4)
#define MAX_SIZE_OF_ERROR_MESSAGE 2048
// error message buffer
class ErrorMessage final {
@@ -179,8 +180,8 @@ class CException {
const char *message) __attribute__((__noreturn__));
static void Raise(const char *filename, int line, ExType extype,
const std::string &message) __attribute__((__noreturn__));
- static void Raise(CException ex, bool reraise) __attribute__((__noreturn__));
- static void ReRaise(CException ex) __attribute__((__noreturn__));
+ static void Raise(CException &ex, bool reraise)
__attribute__((__noreturn__));
+ static void ReRaise(CException &ex) __attribute__((__noreturn__));
private:
char stack_[DEFAULT_STACK_MAX_SIZE];
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]