diff --git a/gfx/graphite2/include/graphite2/Font.h b/gfx/graphite2/include/graphite2/Font.h
--- a/gfx/graphite2/include/graphite2/Font.h
+++ b/gfx/graphite2/include/graphite2/Font.h
@@ -25,17 +25,17 @@
     either version 2 of the License or (at your option) any later version.
 */
 #pragma once
 
 #include "graphite2/Types.h"
 
 #define GR2_VERSION_MAJOR   1
 #define GR2_VERSION_MINOR   1
-#define GR2_VERSION_BUGFIX  2
+#define GR2_VERSION_BUGFIX  3
 
 #ifdef __cplusplus
 extern "C"
 {
 #endif
 
 typedef struct gr_face          gr_face;
 typedef struct gr_font          gr_font;
diff --git a/gfx/graphite2/src/Pass.cpp b/gfx/graphite2/src/Pass.cpp
--- a/gfx/graphite2/src/Pass.cpp
+++ b/gfx/graphite2/src/Pass.cpp
@@ -85,47 +85,49 @@ bool Pass::readPass(const byte * const p
     m_sSuccess = be::read<uint16>(p);
     m_sColumns = be::read<uint16>(p);
     numRanges = be::read<uint16>(p);
     be::skip<uint16>(p, 3); // skip searchRange, entrySelector & rangeShift.
     assert(p - pass_start == 40);
     // Perform some sanity checks.
     if (   m_sTransition > m_sRows
             || m_sSuccess > m_sRows
-            || m_sSuccess + m_sTransition < m_sRows)
+            || m_sSuccess + m_sTransition < m_sRows
+            || numRanges == 0)
         return false;
 
     if (p + numRanges * 6 - 4 > pass_end) return false;
     m_numGlyphs = be::peek<uint16>(p + numRanges * 6 - 4) + 1;
-    // Caculate the start of vairous arrays.
+    // Calculate the start of various arrays.
     const byte * const ranges = p;
     be::skip<uint16>(p, numRanges*3);
     const byte * const o_rule_map = p;
     be::skip<uint16>(p, m_sSuccess + 1);
 
     // More sanity checks
-    if (   reinterpret_cast<const byte *>(o_rule_map + m_sSuccess*sizeof(uint16)) > pass_end
+    if (reinterpret_cast<const byte *>(o_rule_map + m_sSuccess*sizeof(uint16)) > pass_end
             || p > pass_end)
         return false;
     const size_t numEntries = be::peek<uint16>(o_rule_map + m_sSuccess*sizeof(uint16));
     const byte * const   rule_map = p;
     be::skip<uint16>(p, numEntries);
 
-    if (p + 2 > pass_end) return false;
+    if (p + 2*sizeof(uint8) > pass_end) return false;
     m_minPreCtxt = be::read<uint8>(p);
     m_maxPreCtxt = be::read<uint8>(p);
+    if (m_minPreCtxt > m_maxPreCtxt) return false;
     const byte * const start_states = p;
     be::skip<int16>(p, m_maxPreCtxt - m_minPreCtxt + 1);
     const uint16 * const sort_keys = reinterpret_cast<const uint16 *>(p);
     be::skip<uint16>(p, m_numRules);
     const byte * const precontext = p;
     be::skip<byte>(p, m_numRules);
     be::skip<byte>(p);     // skip reserved byte
 
-    if (p + 2 > pass_end) return false;
+    if (p + sizeof(uint16) > pass_end) return false;
     const size_t pass_constraint_len = be::read<uint16>(p);
     const uint16 * const o_constraint = reinterpret_cast<const uint16 *>(p);
     be::skip<uint16>(p, m_numRules + 1);
     const uint16 * const o_actions = reinterpret_cast<const uint16 *>(p);
     be::skip<uint16>(p, m_numRules + 1);
     const byte * const states = p;
     be::skip<int16>(p, m_sTransition*m_sColumns);
     be::skip<byte>(p);          // skip reserved byte
diff --git a/gfx/graphite2/src/inc/Machine.h b/gfx/graphite2/src/inc/Machine.h
--- a/gfx/graphite2/src/inc/Machine.h
+++ b/gfx/graphite2/src/inc/Machine.h
@@ -31,22 +31,31 @@ of the License or (at your option) any l
 // interface.
 
 #pragma once
 #include <cstring>
 #include <graphite2/Types.h>
 #include "inc/Main.h"
 
 #if defined(__GNUC__)
+#if defined(__clang__)
+#define     HOT
+#if defined(__x86_64)
+#define     REGPARM(n)      __attribute__((regparm(n)))
+#else
+#define     REGPARM(n)
+#endif
+#else
 #define     HOT             __attribute__((hot))
 #if defined(__x86_64)
 #define     REGPARM(n)      __attribute__((hot, regparm(n)))
 #else
 #define     REGPARM(n)
 #endif
+#endif
 #else
 #define     HOT
 #define     REGPARM(n)
 #endif
 
 namespace graphite2 {
 
 // Forward declarations
diff --git a/gfx/graphite2/src/json.cpp b/gfx/graphite2/src/json.cpp
--- a/gfx/graphite2/src/json.cpp
+++ b/gfx/graphite2/src/json.cpp
@@ -52,20 +52,20 @@ void json::context(const char current) t
 	fprintf(_stream, "%c", *_context);
 	indent();
 	*_context = current;
 }
 
 
 void json::indent(const int d) throw()
 {
-	if (*_context == member)
+	if (*_context == member || (_flatten  && _flatten < _context))
 		fputc(' ', _stream);
 	else
-		fprintf(_stream, _flatten  && _flatten < _context ? " " : "\n%*s",  4*int(_context - _contexts + d), "");
+		fprintf(_stream,  "\n%*s",  4*int(_context - _contexts + d), "");
 }
 
 
 inline
 void json::push_context(const char prefix, const char suffix) throw()
 {
 	assert(_context - _contexts < std::ptrdiff_t(sizeof _contexts));
 
