File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,6 +49,12 @@ template <> struct string_traits<pgvector::Vector> {
4949 static std::string_view to_buf (std::span<char > buf, const pgvector::Vector& value, ctx c = {}) {
5050 auto values = static_cast <std::vector<float >>(value);
5151
52+ // important! size_buffer cannot throw an exception on overflow
53+ // so perform this check before writing any data
54+ if (values.size () > 16000 ) {
55+ throw conversion_overrun{" vector cannot have more than 16000 dimensions" };
56+ }
57+
5258 size_t here = 0 ;
5359 buf[here++] = ' [' ;
5460
@@ -103,6 +109,12 @@ template <> struct string_traits<pgvector::HalfVector> {
103109 static std::string_view to_buf (std::span<char > buf, const pgvector::HalfVector& value, ctx c = {}) {
104110 auto values = static_cast <std::vector<float >>(value);
105111
112+ // important! size_buffer cannot throw an exception on overflow
113+ // so perform this check before writing any data
114+ if (values.size () > 16000 ) {
115+ throw conversion_overrun{" halfvec cannot have more than 16000 dimensions" };
116+ }
117+
106118 size_t here = 0 ;
107119 buf[here++] = ' [' ;
108120
You can’t perform that action at this time.
0 commit comments