Skip to content

Commit 2b53475

Browse files
committed
Fix #7472 - Window functions may lead to crash interacting with others exceptions.
1 parent 4b4c26b commit 2b53475

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/jrd/recsrc/RecordSource.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,15 @@ namespace Jrd
765765
return savedPosition;
766766
}
767767

768+
void restore()
769+
{
770+
if (!moved)
771+
return;
772+
773+
// Position the stream where we received it.
774+
moveWithinPartition(0);
775+
}
776+
768777
bool moveWithinPartition(SINT64 delta);
769778
bool moveWithinFrame(SINT64 delta);
770779

@@ -776,7 +785,7 @@ namespace Jrd
776785
FB_UINT64 frameStart;
777786
FB_UINT64 frameEnd;
778787
FB_UINT64 savedPosition;
779-
bool moved;
788+
bool moved = false;
780789
};
781790

782791
template <typename ThisType, typename NextType>

src/jrd/recsrc/WindowedStream.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#include "../jrd/par_proto.h"
2929
#include "../jrd/vio_proto.h"
3030
#include "../jrd/optimizer/Optimizer.h"
31-
3231
#include "RecordSource.h"
32+
#include <exception>
3333

3434
using namespace Firebird;
3535
using namespace Jrd;
@@ -862,7 +862,7 @@ bool WindowedStream::WindowStream::internalGetRecord(thread_db* tdbb) const
862862
record->clearNull(id);
863863
}
864864

865-
window.moveWithinPartition(0);
865+
window.restore();
866866
}
867867
}
868868

@@ -1078,19 +1078,20 @@ SlidingWindow::SlidingWindow(thread_db* aTdbb, const BaseBufferedStream* aStream
10781078
partitionStart(aPartitionStart),
10791079
partitionEnd(aPartitionEnd),
10801080
frameStart(aFrameStart),
1081-
frameEnd(aFrameEnd),
1082-
moved(false)
1081+
frameEnd(aFrameEnd)
10831082
{
10841083
savedPosition = stream->getPosition(request) - 1;
10851084
}
10861085

10871086
SlidingWindow::~SlidingWindow()
10881087
{
1089-
if (!moved)
1090-
return;
1091-
1092-
// Position the stream where we received it.
1093-
moveWithinPartition(0);
1088+
#ifdef DEV_BUILD
1089+
#if __cpp_lib_uncaught_exceptions >= 201411L
1090+
fb_assert(!moved || std::uncaught_exceptions());
1091+
#else
1092+
fb_assert(!moved || std::uncaught_exception());
1093+
#endif
1094+
#endif
10941095
}
10951096

10961097
// Move in the window without pass partition boundaries.
@@ -1101,7 +1102,7 @@ bool SlidingWindow::moveWithinPartition(SINT64 delta)
11011102
if (newPosition < partitionStart || newPosition > partitionEnd)
11021103
return false;
11031104

1104-
moved = true;
1105+
moved = delta != 0;
11051106

11061107
stream->locate(tdbb, newPosition);
11071108

0 commit comments

Comments
 (0)