summaryrefslogtreecommitdiff
path: root/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh
diff options
context:
space:
mode:
authorAkira Kakuto <kakuto@fuk.kindai.ac.jp>2021-05-05 22:28:05 +0000
committerAkira Kakuto <kakuto@fuk.kindai.ac.jp>2021-05-05 22:28:05 +0000
commitae18810d9334b628179c2aa19d06cfade25955cb (patch)
tree917ba096243e08241a3ee5ecb37890df6fe53566 /Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh
parent04c30db0018970c69516d748c7b4509240857b65 (diff)
harfbuzz 2.8.1
git-svn-id: svn://tug.org/texlive/trunk@59092 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh')
-rw-r--r--Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh89
1 files changed, 66 insertions, 23 deletions
diff --git a/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh b/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh
index fe29bdf96ee..3ec055b7b0b 100644
--- a/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh
+++ b/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-serialize.hh
@@ -41,6 +41,16 @@
* Serialize
*/
+enum hb_serialize_error_t {
+ HB_SERIALIZE_ERROR_NONE = 0x00000000u,
+ HB_SERIALIZE_ERROR_OTHER = 0x00000001u,
+ HB_SERIALIZE_ERROR_OFFSET_OVERFLOW = 0x00000002u,
+ HB_SERIALIZE_ERROR_OUT_OF_ROOM = 0x00000004u,
+ HB_SERIALIZE_ERROR_INT_OVERFLOW = 0x00000008u,
+ HB_SERIALIZE_ERROR_ARRAY_OVERFLOW = 0x00000010u
+};
+HB_MARK_AS_FLAG_T (hb_serialize_error_t);
+
struct hb_serialize_context_t
{
typedef unsigned objidx_t;
@@ -51,6 +61,8 @@ struct hb_serialize_context_t
Absolute /* Absolute: from the start of the serialize buffer. */
};
+
+
struct object_t
{
void fini () { links.fini (); }
@@ -117,30 +129,54 @@ struct hb_serialize_context_t
object_pool.fini ();
}
- bool in_error () const { return !this->successful; }
+ bool in_error () const { return bool (errors); }
+
+ bool successful () const { return !bool (errors); }
+
+ HB_NODISCARD bool ran_out_of_room () const { return errors & HB_SERIALIZE_ERROR_OUT_OF_ROOM; }
+ HB_NODISCARD bool offset_overflow () const { return errors & HB_SERIALIZE_ERROR_OFFSET_OVERFLOW; }
+ HB_NODISCARD bool only_offset_overflow () const { return errors == HB_SERIALIZE_ERROR_OFFSET_OVERFLOW; }
+
+ void reset (void *start_, unsigned int size)
+ {
+ start = (char*) start_;
+ end = start + size;
+ reset ();
+ current = nullptr;
+ }
void reset ()
{
- this->successful = true;
- this->ran_out_of_room = false;
+ this->errors = HB_SERIALIZE_ERROR_NONE;
this->head = this->start;
this->tail = this->end;
this->debug_depth = 0;
fini ();
this->packed.push (nullptr);
+ this->packed_map.init ();
}
- bool check_success (bool success)
- { return this->successful && (success || (err_other_error (), false)); }
+ bool check_success (bool success,
+ hb_serialize_error_t err_type = HB_SERIALIZE_ERROR_OTHER)
+ {
+ return successful ()
+ && (success || err (err_type));
+ }
template <typename T1, typename T2>
- bool check_equal (T1 &&v1, T2 &&v2)
- { return check_success ((long long) v1 == (long long) v2); }
+ bool check_equal (T1 &&v1, T2 &&v2, hb_serialize_error_t err_type)
+ {
+ if ((long long) v1 != (long long) v2)
+ {
+ return err (err_type);
+ }
+ return true;
+ }
template <typename T1, typename T2>
- bool check_assign (T1 &v1, T2 &&v2)
- { return check_equal (v1 = v2, v2); }
+ bool check_assign (T1 &v1, T2 &&v2, hb_serialize_error_t err_type)
+ { return check_equal (v1 = v2, v2, err_type); }
template <typename T> bool propagate_error (T &&obj)
{ return check_success (!hb_deref (obj).in_error ()); }
@@ -167,12 +203,18 @@ struct hb_serialize_context_t
"end [%p..%p] serialized %u bytes; %s",
this->start, this->end,
(unsigned) (this->head - this->start),
- this->successful ? "successful" : "UNSUCCESSFUL");
+ successful () ? "successful" : "UNSUCCESSFUL");
propagate_error (packed, packed_map);
if (unlikely (!current)) return;
- if (unlikely (in_error())) return;
+ if (unlikely (in_error()))
+ {
+ // Offset overflows that occur before link resolution cannot be handled
+ // by repacking, so set a more general error.
+ if (offset_overflow ()) err (HB_SERIALIZE_ERROR_OTHER);
+ return;
+ }
assert (!current->next);
@@ -351,7 +393,7 @@ struct hb_serialize_context_t
for (const object_t::link_t &link : parent->links)
{
const object_t* child = packed[link.objidx];
- if (unlikely (!child)) { err_other_error(); return; }
+ if (unlikely (!child)) { err (HB_SERIALIZE_ERROR_OTHER); return; }
unsigned offset = 0;
switch ((whence_t) link.whence) {
case Head: offset = child->head - parent->head; break;
@@ -398,19 +440,19 @@ struct hb_serialize_context_t
Type *start_embed (const Type &obj) const
{ return start_embed (hb_addressof (obj)); }
- /* Following two functions exist to allow setting breakpoint on. */
- void err_ran_out_of_room () { this->ran_out_of_room = true; }
- void err_other_error () { this->successful = false; }
+ bool err (hb_serialize_error_t err_type)
+ {
+ return !bool ((errors = (errors | err_type)));
+ }
template <typename Type>
Type *allocate_size (unsigned int size)
{
- if (unlikely (!this->successful)) return nullptr;
+ if (unlikely (in_error ())) return nullptr;
if (this->tail - this->head < ptrdiff_t (size))
{
- err_ran_out_of_room ();
- this->successful = false;
+ err (HB_SERIALIZE_ERROR_OUT_OF_ROOM);
return nullptr;
}
memset (this->head, 0, size);
@@ -497,7 +539,7 @@ struct hb_serialize_context_t
/* Output routines. */
hb_bytes_t copy_bytes () const
{
- assert (this->successful);
+ assert (successful ());
/* Copy both items from head side and tail side... */
unsigned int len = (this->head - this->start)
+ (this->end - this->tail);
@@ -520,20 +562,22 @@ struct hb_serialize_context_t
(char *) b.arrayZ, free);
}
+ const hb_vector_t<object_t *>& object_graph() const
+ { return packed; }
+
private:
template <typename T>
void assign_offset (const object_t* parent, const object_t::link_t &link, unsigned offset)
{
auto &off = * ((BEInt<T> *) (parent->head + link.position));
assert (0 == off);
- check_assign (off, offset);
+ check_assign (off, offset, HB_SERIALIZE_ERROR_OFFSET_OVERFLOW);
}
public: /* TODO Make private. */
char *start, *head, *tail, *end;
unsigned int debug_depth;
- bool successful;
- bool ran_out_of_room;
+ hb_serialize_error_t errors;
private:
@@ -550,5 +594,4 @@ struct hb_serialize_context_t
hb_hashmap_t<const object_t *, objidx_t, nullptr, 0> packed_map;
};
-
#endif /* HB_SERIALIZE_HH */