aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorswarmer <swarmer@yandex-team.com>2024-02-11 22:08:52 +0300
committerswarmer <swarmer@yandex-team.com>2024-02-11 22:23:05 +0300
commitdb26b26fad338fdc3b6b326374b9a53b1c75dd7d (patch)
treeeab61984739aca8cef8ef88f0742b942b7c868d3
parentd00b2e410ece1c94481b5fb62df5780c8d870ab4 (diff)
downloadydb-db26b26fad338fdc3b6b326374b9a53b1c75dd7d.tar.gz
fix use-after-free in the IModelsArchiveReader class
The implementation has also been moved into a cpp file.
-rw-r--r--library/cpp/archive/models_archive_reader.cpp15
-rw-r--r--library/cpp/archive/models_archive_reader.h12
-rw-r--r--library/cpp/archive/ya.make1
3 files changed, 17 insertions, 11 deletions
diff --git a/library/cpp/archive/models_archive_reader.cpp b/library/cpp/archive/models_archive_reader.cpp
new file mode 100644
index 0000000000..abbb91d628
--- /dev/null
+++ b/library/cpp/archive/models_archive_reader.cpp
@@ -0,0 +1,15 @@
+#include "models_archive_reader.h"
+
+#include <util/generic/hash_set.h>
+
+THashSet<TStringBuf> IModelsArchiveReader::FilterByPrefix(TStringBuf prefix, TStringBuf suffix) const {
+ THashSet<TStringBuf> result;
+ const size_t count = Count();
+ for (size_t ind = 0; ind < count; ++ind) {
+ TString path = KeyByIndex(ind);
+ if (path.StartsWith(prefix) && path.EndsWith(suffix)) {
+ result.insert(std::move(path));
+ }
+ }
+ return result;
+}
diff --git a/library/cpp/archive/models_archive_reader.h b/library/cpp/archive/models_archive_reader.h
index a5731b01cb..12347bf55e 100644
--- a/library/cpp/archive/models_archive_reader.h
+++ b/library/cpp/archive/models_archive_reader.h
@@ -2,7 +2,6 @@
#include <util/generic/fwd.h>
#include <util/generic/ptr.h>
-#include <util/generic/hash_set.h>
class IInputStream;
@@ -18,14 +17,5 @@ public:
virtual TBlob ObjectBlobByKey(const TStringBuf key) const = 0;
virtual TBlob BlobByKey(const TStringBuf key) const = 0;
virtual bool Compressed() const = 0;
- virtual THashSet<TStringBuf> FilterByPrefix(TStringBuf prefix, TStringBuf suffix) const {
- THashSet<TStringBuf> result;
- for (size_t ind = 0; ind < Count(); ++ind) {
- TStringBuf path = KeyByIndex(ind);
- if (path.StartsWith(prefix) && path.EndsWith(suffix)) {
- result.insert(path);
- }
- }
- return result;
- }
+ virtual THashSet<TStringBuf> FilterByPrefix(TStringBuf prefix, TStringBuf suffix) const;
};
diff --git a/library/cpp/archive/ya.make b/library/cpp/archive/ya.make
index ff20c9ffbd..613c370dba 100644
--- a/library/cpp/archive/ya.make
+++ b/library/cpp/archive/ya.make
@@ -5,6 +5,7 @@ SRCS(
yarchive.h
directory_models_archive_reader.cpp
directory_models_archive_reader.h
+ models_archive_reader.cpp
)
END()