8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 19:23:03 +01:00

Fix #7472 - Window functions may lead to crash interacting with others exceptions.

This commit is contained in:
Adriano dos Santos Fernandes 2023-02-11 11:12:59 -03:00
parent 5296ca6d13
commit da83e4728c
2 changed files with 21 additions and 10 deletions

View File

@ -670,6 +670,15 @@ namespace Jrd
return savedPosition;
}
void restore()
{
if (!moved)
return;
// Position the stream where we received it.
moveWithinPartition(0);
}
bool moveWithinPartition(SINT64 delta);
bool moveWithinFrame(SINT64 delta);
@ -681,7 +690,7 @@ namespace Jrd
FB_UINT64 frameStart;
FB_UINT64 frameEnd;
FB_UINT64 savedPosition;
bool moved;
bool moved = false;
};
template <typename ThisType, typename NextType>

View File

@ -28,6 +28,7 @@
#include "../jrd/exe_proto.h"
#include "../jrd/par_proto.h"
#include "RecordSource.h"
#include <exception>
using namespace Firebird;
using namespace Jrd;
@ -842,7 +843,7 @@ bool WindowedStream::WindowStream::getRecord(thread_db* tdbb) const
record->clearNull(id);
}
window.moveWithinPartition(0);
window.restore();
}
}
@ -1054,19 +1055,20 @@ SlidingWindow::SlidingWindow(thread_db* aTdbb, const BaseBufferedStream* aStream
partitionStart(aPartitionStart),
partitionEnd(aPartitionEnd),
frameStart(aFrameStart),
frameEnd(aFrameEnd),
moved(false)
frameEnd(aFrameEnd)
{
savedPosition = stream->getPosition(request) - 1;
}
SlidingWindow::~SlidingWindow()
{
if (!moved)
return;
// Position the stream where we received it.
moveWithinPartition(0);
#ifdef DEV_BUILD
#if __cpp_lib_uncaught_exceptions >= 201411L
fb_assert(!moved || std::uncaught_exceptions());
#else
fb_assert(!moved || std::uncaught_exception());
#endif
#endif
}
// Move in the window without pass partition boundaries.
@ -1077,7 +1079,7 @@ bool SlidingWindow::moveWithinPartition(SINT64 delta)
if (newPosition < partitionStart || newPosition > partitionEnd)
return false;
moved = true;
moved = delta != 0;
stream->locate(tdbb, newPosition);