Skip to content

Commit

Permalink
Show invalid table tags as hex in error messages.
Browse files Browse the repository at this point in the history
This avoids the risk of the returned message including NUL or other
non-printing characters.

(See https://bugzilla.mozilla.org/show_bug.cgi?id=1937227 for the
example that motivated this change.)
  • Loading branch information
jfkthame committed Jan 2, 2025
1 parent ea789e2 commit 29452f9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/ots.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,18 @@ bool CheckTag(uint32_t tag_value) {

namespace {

#define OTS_MSG_TAG_(level,otf_,msg_,tag_) \
(OTS_MESSAGE_(level,otf_,"%c%c%c%c: %s", OTS_UNTAG(tag_), msg_), false)
// ots_msg_tag emits the tag as hex if it is not valid, to avoid putting NUL or
// other non-printables into the message string.
static inline void ots_msg_tag(int level, const ots::FontFile* otf, const char* msg, uint32_t tag) {
if (ots::CheckTag(tag)) {
OTS_MESSAGE_(level, otf, "%c%c%c%c: %s", OTS_UNTAG(tag), msg);
} else {
OTS_MESSAGE_(level, otf, "<%08X>: %s", tag, msg);
}
}

// Generate a message with or without a table tag, when 'header' is the FontFile pointer
#define OTS_FAILURE_MSG_TAG(msg_,tag_) OTS_MSG_TAG_(0, header, msg_, tag_)
#define OTS_FAILURE_MSG_TAG(msg_,tag_) (ots_msg_tag(0, header, msg_, tag_), false)
#define OTS_FAILURE_MSG_HDR(...) OTS_FAILURE_MSG_(header, __VA_ARGS__)
#define OTS_WARNING_MSG_HDR(...) OTS_WARNING_MSG_(header, __VA_ARGS__)

Expand Down

0 comments on commit 29452f9

Please sign in to comment.