Prevent JS from creating css::uno::Sequence of negative size

Change-Id: I2449723162744e9ce3cb3e3172ce8acae0adf4db
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162998
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
This commit is contained in:
Stephan Bergmann
2024-02-05 12:54:38 +01:00
parent 6b68491075
commit f289fe3dca

View File

@@ -52,6 +52,14 @@ template <typename T> struct UnoInOutParam
T value;
};
inline void checkSequenceSize(sal_Int32 size)
{
if (size < 0)
{
throw std::invalid_argument("negative size");
}
}
template <typename T>
void checkSequenceAccess(css::uno::Sequence<T> const& sequence, sal_Int32 index)
{
@@ -64,13 +72,13 @@ void checkSequenceAccess(css::uno::Sequence<T> const& sequence, sal_Int32 index)
template <typename T> void registerSequence(char const* name)
{
emscripten::class_<css::uno::Sequence<T>>(name)
.template constructor<sal_Int32>()
.constructor(+[](sal_Int32 size) {
checkSequenceSize(size);
return css::uno::Sequence<T>(size);
})
.function("resize",
+[](css::uno::Sequence<T>& self, sal_Int32 size) {
if (size < 0)
{
throw std::invalid_argument("negative size");
}
checkSequenceSize(size);
self.realloc(size);
})
.function("size", &css::uno::Sequence<T>::getLength)