From cc577ce8c5e051967fce0ae954f78874e400c2f8 Mon Sep 17 00:00:00 2001 From: Akira Kakuto Date: Mon, 5 Mar 2018 09:10:55 +0000 Subject: graphite2-1.3.11 git-svn-id: svn://tug.org/texlive/trunk@46828 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/libs/graphite2/ChangeLog | 5 ++ Build/source/libs/graphite2/TLpatches/ChangeLog | 5 ++ Build/source/libs/graphite2/TLpatches/TL-Changes | 2 +- Build/source/libs/graphite2/configure | 20 ++++---- .../libs/graphite2/graphite2-src/CMakeLists.txt | 5 ++ .../source/libs/graphite2/graphite2-src/ChangeLog | 5 ++ .../source/libs/graphite2/graphite2-src/README.md | 7 +++ .../graphite2-src/include/graphite2/Font.h | 2 +- .../graphite2/graphite2-src/src/CMakeLists.txt | 22 +++++--- .../libs/graphite2/graphite2-src/src/Code.cpp | 9 +++- .../libs/graphite2/graphite2-src/src/Collider.cpp | 33 ++++++++---- .../graphite2/graphite2-src/src/Decompressor.cpp | 59 +++++++++++++--------- .../graphite2/graphite2-src/src/FeatureMap.cpp | 24 ++++----- .../libs/graphite2/graphite2-src/src/FileFace.cpp | 2 +- .../libs/graphite2/graphite2-src/src/Pass.cpp | 24 +++++---- .../graphite2/graphite2-src/src/SegCacheEntry.cpp | 2 +- .../libs/graphite2/graphite2-src/src/Segment.cpp | 4 +- .../libs/graphite2/graphite2-src/src/Silf.cpp | 1 + .../libs/graphite2/graphite2-src/src/TtfUtil.cpp | 9 +++- .../libs/graphite2/graphite2-src/src/gr_face.cpp | 2 +- .../graphite2/graphite2-src/src/gr_features.cpp | 10 ++-- .../libs/graphite2/graphite2-src/src/gr_font.cpp | 12 +++-- .../graphite2/graphite2-src/src/gr_logging.cpp | 5 +- .../graphite2/graphite2-src/src/gr_segment.cpp | 4 +- .../libs/graphite2/graphite2-src/src/inc/Code.h | 2 +- .../graphite2/graphite2-src/src/inc/Collider.h | 4 +- .../graphite2/graphite2-src/src/inc/Compression.h | 5 +- .../graphite2/graphite2-src/src/inc/FeatureMap.h | 20 ++------ .../libs/graphite2/graphite2-src/src/inc/Font.h | 1 + .../libs/graphite2/graphite2-src/src/inc/List.h | 5 +- .../libs/graphite2/graphite2-src/src/inc/Machine.h | 25 +++++---- .../libs/graphite2/graphite2-src/src/inc/Main.h | 58 +++++++++++++++++++-- .../libs/graphite2/graphite2-src/src/inc/Segment.h | 2 +- .../libs/graphite2/graphite2-src/src/inc/Sparse.h | 9 ++-- .../graphite2/graphite2-src/src/inc/opcode_table.h | 2 +- .../libs/graphite2/graphite2-src/src/inc/opcodes.h | 19 ++++--- Build/source/libs/graphite2/version.ac | 2 +- 37 files changed, 281 insertions(+), 146 deletions(-) (limited to 'Build/source/libs/graphite2') diff --git a/Build/source/libs/graphite2/ChangeLog b/Build/source/libs/graphite2/ChangeLog index 93c0ed82fe4..3422be53ead 100644 --- a/Build/source/libs/graphite2/ChangeLog +++ b/Build/source/libs/graphite2/ChangeLog @@ -1,3 +1,8 @@ +2018-03-05 Akira Kakuto + + Import graphite2-1.3.11. + * version.ac: Adjusted. + 2017-06-20 Akira Kakuto Import graphite2-1.3.10. diff --git a/Build/source/libs/graphite2/TLpatches/ChangeLog b/Build/source/libs/graphite2/TLpatches/ChangeLog index 3ca3df28b2f..ff3748e8c4c 100644 --- a/Build/source/libs/graphite2/TLpatches/ChangeLog +++ b/Build/source/libs/graphite2/TLpatches/ChangeLog @@ -1,3 +1,8 @@ +2018-03-05 Akira Kakuto + + Imported graphite2-1.3.11 source tree from: + http://sourceforge.net/projects/silgraphite/files/graphite2/ + 2017-06-20 Akira Kakuto Imported graphite2-1.3.10 source tree from: diff --git a/Build/source/libs/graphite2/TLpatches/TL-Changes b/Build/source/libs/graphite2/TLpatches/TL-Changes index 9897d7887a7..32e9d5af6ad 100644 --- a/Build/source/libs/graphite2/TLpatches/TL-Changes +++ b/Build/source/libs/graphite2/TLpatches/TL-Changes @@ -1,4 +1,4 @@ -Changes applied to the graphite2-1.3.10/ tree as obtained from: +Changes applied to the graphite2-1.3.11/ tree as obtained from: http://sourceforge.net/projects/silgraphite/files/graphite2/ Removed unused dirs: diff --git a/Build/source/libs/graphite2/configure b/Build/source/libs/graphite2/configure index 43de86dd7a5..5c6d4944e1c 100755 --- a/Build/source/libs/graphite2/configure +++ b/Build/source/libs/graphite2/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for graphite2 (TeX Live) 1.3.10. +# Generated by GNU Autoconf 2.69 for graphite2 (TeX Live) 1.3.11. # # Report bugs to . # @@ -579,8 +579,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='graphite2 (TeX Live)' PACKAGE_TARNAME='graphite2--tex-live-' -PACKAGE_VERSION='1.3.10' -PACKAGE_STRING='graphite2 (TeX Live) 1.3.10' +PACKAGE_VERSION='1.3.11' +PACKAGE_STRING='graphite2 (TeX Live) 1.3.11' PACKAGE_BUGREPORT='tex-k@tug.org' PACKAGE_URL='' @@ -1254,7 +1254,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures graphite2 (TeX Live) 1.3.10 to adapt to many kinds of systems. +\`configure' configures graphite2 (TeX Live) 1.3.11 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1321,7 +1321,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of graphite2 (TeX Live) 1.3.10:";; + short | recursive ) echo "Configuration of graphite2 (TeX Live) 1.3.11:";; esac cat <<\_ACEOF @@ -1419,7 +1419,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -graphite2 (TeX Live) configure 1.3.10 +graphite2 (TeX Live) configure 1.3.11 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1558,7 +1558,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by graphite2 (TeX Live) $as_me 1.3.10, which was +It was created by graphite2 (TeX Live) $as_me 1.3.11, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -3481,7 +3481,7 @@ fi # Define the identity of the package. PACKAGE='graphite2--tex-live-' - VERSION='1.3.10' + VERSION='1.3.11' cat >>confdefs.h <<_ACEOF @@ -5577,7 +5577,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by graphite2 (TeX Live) $as_me 1.3.10, which was +This file was extended by graphite2 (TeX Live) $as_me 1.3.11, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -5643,7 +5643,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -graphite2 (TeX Live) config.status 1.3.10 +graphite2 (TeX Live) config.status 1.3.11 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/Build/source/libs/graphite2/graphite2-src/CMakeLists.txt b/Build/source/libs/graphite2/graphite2-src/CMakeLists.txt index bb8d75bd63a..3466c5fc0d3 100644 --- a/Build/source/libs/graphite2/graphite2-src/CMakeLists.txt +++ b/Build/source/libs/graphite2/graphite2-src/CMakeLists.txt @@ -8,6 +8,8 @@ if (NOT CMAKE_BUILD_TYPE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE Release) endif (NOT CMAKE_BUILD_TYPE) +option(BUILD_SHARED_LIBS "Make library a shared library instead of static" ON) + enable_language(CXX C) include_directories(${PROJECT_SOURCE_DIR}/include) @@ -23,12 +25,15 @@ option(GRAPHITE2_ASAN "Enable Address Sanitizing") message(STATUS "Build: " ${CMAKE_BUILD_TYPE}) +string(REPLACE "ON" "shared" _LIB_OBJECT_TYPE ${BUILD_SHARED_LIBS}) +string(REPLACE "OFF" "static" _LIB_OBJECT_TYPE ${_LIB_OBJECT_TYPE}) string(REPLACE "ON" "disabled" _SEGCACHE_SUPPORT ${GRAPHITE2_NSEGCACHE}) string(REPLACE "OFF" "enabled" _SEGCACHE_SUPPORT ${_SEGCACHE_SUPPORT}) string(REPLACE "ON" "disabled" _FILEFACE_SUPPORT ${GRAPHITE2_NFILEFACE}) string(REPLACE "OFF" "enabled" _FILEFACE_SUPPORT ${_FILEFACE_SUPPORT}) string(REPLACE "ON" "disabled" _TRACING_SUPPORT ${GRAPHITE2_NTRACING}) string(REPLACE "OFF" "enabled" _TRACING_SUPPORT ${_TRACING_SUPPORT}) +message(STATUS "Building library: " ${_LIB_OBJECT_TYPE}) message(STATUS "Segment Cache support: " ${_SEGCACHE_SUPPORT}) message(STATUS "File Face support: " ${_FILEFACE_SUPPORT}) message(STATUS "Tracing support: " ${_TRACING_SUPPORT}) diff --git a/Build/source/libs/graphite2/graphite2-src/ChangeLog b/Build/source/libs/graphite2/graphite2-src/ChangeLog index 026feda56a4..0a824ff42fe 100644 --- a/Build/source/libs/graphite2/graphite2-src/ChangeLog +++ b/Build/source/libs/graphite2/graphite2-src/ChangeLog @@ -1,3 +1,8 @@ +1.3.11 + . Fixes due to security review + . Minor collision avoidance fixes + . Fix LZ4 decompressor against high compression + 1.3.10 . Address floating point build parameters to give consistent positioning results across platforms . Various bug fixes diff --git a/Build/source/libs/graphite2/graphite2-src/README.md b/Build/source/libs/graphite2/graphite2-src/README.md index 2c4ecf58d8a..d6db43a2624 100644 --- a/Build/source/libs/graphite2/graphite2-src/README.md +++ b/Build/source/libs/graphite2/graphite2-src/README.md @@ -1,5 +1,12 @@ # Graphite engine +## Project CI status +Linux -- Intel 64bit:[![Build Status](http://build.palaso.org/app/rest/builds/buildType:bt124/statusIcon)](http://build.palaso.org/viewType.html?buildTypeId=bt124&guest=1) +Intel 32bit:[![Build Status](http://build.palaso.org/app/rest/builds/buildType:bt123/statusIcon)](http://build.palaso.org/viewType.html?buildTypeId=bt123&guest=1) +ARM 32bit:[![Build Status](http://build.palaso.org/app/rest/builds/buildType:Graphite_Linux32bitArm/statusIcon)](http://build.palaso.org/viewType.html?buildTypeId=Graphite_Linux32bitArm&guest=1) + +Windows -- Intel 64bit:[![Build Status](http://build.palaso.org/app/rest/builds/buildType:Graphite_Windows64bitProduction/statusIcon)](http://build.palaso.org/viewType.html?buildTypeId=Graphite_Windows64bitProduction&guest=1) + ## What is Graphite? Graphite is a system that can be used to create “smart fonts” capable of displaying writing systems with various complex behaviors. A smart font contains not only letter shapes but also additional instructions indicating how to combine and position the letters in complex ways. diff --git a/Build/source/libs/graphite2/graphite2-src/include/graphite2/Font.h b/Build/source/libs/graphite2/graphite2-src/include/graphite2/Font.h index 729ebff88ab..efe2af9f247 100644 --- a/Build/source/libs/graphite2/graphite2-src/include/graphite2/Font.h +++ b/Build/source/libs/graphite2/graphite2-src/include/graphite2/Font.h @@ -30,7 +30,7 @@ #define GR2_VERSION_MAJOR 1 #define GR2_VERSION_MINOR 3 -#define GR2_VERSION_BUGFIX 10 +#define GR2_VERSION_BUGFIX 11 #ifdef __cplusplus extern "C" diff --git a/Build/source/libs/graphite2/graphite2-src/src/CMakeLists.txt b/Build/source/libs/graphite2/graphite2-src/src/CMakeLists.txt index 08e1c8fa3d7..aa42dbb0d52 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/CMakeLists.txt +++ b/Build/source/libs/graphite2/graphite2-src/src/CMakeLists.txt @@ -56,6 +56,10 @@ if (GRAPHITE2_TELEMETRY) add_definitions(-DGRAPHITE2_TELEMETRY) endif (GRAPHITE2_TELEMETRY) +if (NOT BUILD_SHARED_LIBS) + add_definitions(-DGRAPHITE2_STATIC) +endif (NOT BUILD_SHARED_LIBS) + set(GRAPHITE_HEADERS ../include/graphite2/Font.h ../include/graphite2/Segment.h @@ -65,7 +69,7 @@ set(GRAPHITE_HEADERS file(GLOB PRIVATE_HEADERS inc/*.h) -add_library(graphite2 SHARED +add_library(graphite2 ${GRAPHITE2_VM_TYPE}_machine.cpp gr_char_info.cpp gr_features.cpp @@ -107,9 +111,9 @@ set_target_properties(graphite2 PROPERTIES PUBLIC_HEADER "${GRAPHITE_HEADERS}" LT_VERSION_AGE ${GRAPHITE_API_AGE}) if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - set_target_properties(graphite2 PROPERTIES - COMPILE_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -Wendif-labels -Wshadow -Wctor-dtor-privacy -Wnon-virtual-dtor -fno-rtti -fno-exceptions -fvisibility=hidden -fvisibility-inlines-hidden -fno-stack-protector" - LINK_FLAGS "-nodefaultlibs ${GRAPHITE_LINK_FLAGS}" + set_target_properties(graphite2 PROPERTIES + COMPILE_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -Wendif-labels -Wshadow -Wctor-dtor-privacy -Wnon-virtual-dtor -fno-rtti -fno-exceptions -fvisibility=hidden -fvisibility-inlines-hidden" + LINK_FLAGS "-nodefaultlibs ${GRAPHITE_LINK_FLAGS}" LINKER_LANGUAGE C) if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86|i.86") add_definitions(-mfpmath=sse -msse2) @@ -130,16 +134,18 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") target_link_libraries(graphite2 c gcc) endif (GRAPHITE2_ASAN) include(Graphite) - nolib_test(stdc++ $) + if (BUILD_SHARED_LIBS) + nolib_test(stdc++ $) + endif (BUILD_SHARED_LIBS) endif (${CMAKE_CXX_COMPILER} MATCHES ".*mingw.*") set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") CREATE_LIBTOOL_FILE(graphite2 "/lib${LIB_SUFFIX}") endif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") - set_target_properties(graphite2 PROPERTIES - COMPILE_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -Wimplicit-fallthrough -Wendif-labels -Wshadow -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -fno-rtti -fno-exceptions -fvisibility=hidden -fvisibility-inlines-hidden -fno-stack-protector -mfpmath=sse -msse2" - LINK_FLAGS "-nodefaultlibs" + set_target_properties(graphite2 PROPERTIES + COMPILE_FLAGS "-Wall -Wextra -Wno-unknown-pragmas -Wimplicit-fallthrough -Wendif-labels -Wshadow -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -fno-rtti -fno-exceptions -fvisibility=hidden -fvisibility-inlines-hidden -mfpmath=sse -msse2" + LINK_FLAGS "-nodefaultlibs" LINKER_LANGUAGE C) target_link_libraries(graphite2 c) include(Graphite) diff --git a/Build/source/libs/graphite2/graphite2-src/src/Code.cpp b/Build/source/libs/graphite2/graphite2-src/src/Code.cpp index 92ba92379cb..4497eea4c53 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/Code.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/Code.cpp @@ -219,7 +219,11 @@ Machine::Code::Code(bool is_constraint, const byte * bytecode_begin, const byte if (_out) *_out += total_sz; else - _code = static_cast(realloc(_code, total_sz)); + { + instr * const old_code = _code; + _code = static_cast(realloc(_code, total_sz)); + if (!_code) free(old_code); + } _data = reinterpret_cast(_code + (_instr_count+1)); if (!_code) @@ -316,8 +320,9 @@ opcode Machine::Code::decoder::fetch_opcode(const byte * bc) if (_stack_depth <= 0) failure(underfull_stack); break; - case NEXT : case NEXT_N : // runtime checked + break; + case NEXT : case COPY_NEXT : ++_out_index; if (_out_index < -1 || _out_index > _out_length || _slotref > _max.rule_length) diff --git a/Build/source/libs/graphite2/graphite2-src/src/Collider.cpp b/Build/source/libs/graphite2/graphite2-src/src/Collider.cpp index 035bb9a3125..d82163aadc2 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/Collider.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/Collider.cpp @@ -306,7 +306,7 @@ bool ShiftCollider::mergeSlot(Segment *seg, Slot *slot, const SlotCollision *csl float seq_above_wt = cslot->seqAboveWt(); float seq_below_wt = cslot->seqBelowWt(); float seq_valign_wt = cslot->seqValignWt(); - float lmargin = _margin; + float lmargin; // if isAfter, invert orderFlags for diagonal orders. if (isAfter) { @@ -558,6 +558,8 @@ bool ShiftCollider::mergeSlot(Segment *seg, Slot *slot, const SlotCollision *csl { // Set up the bogus slot representing the exclusion glyph. Slot *exclSlot = seg->newSlot(); + if (!exclSlot) + return res; exclSlot->setGlyph(seg, cslot->exclGlyph()); Position exclOrigin(slot->origin() + cslot->exclOffset()); exclSlot->origin(exclOrigin); @@ -805,6 +807,8 @@ static float get_edge(Segment *seg, const Slot *s, const Position &shift, float { const BBox &bb = gc.getBoundingBBox(gid); const SlantBox &sb = gc.getBoundingSlantBox(gid); + if (sy + bb.yi - margin > y + width / 2 || sy + bb.ya + margin < y - width / 2) + return res; float td = sx - sy + y; float ts = sx + sy - y; if (isRight) @@ -924,7 +928,7 @@ bool KernCollider::initSlot(Segment *seg, Slot *aSlot, const Rect &limit, float } } done: - _mingap = (float)1e38; + _mingap = (float)1e37; // less than 1e38 s.t. 1e38-_mingap is really big _target = aSlot; _margin = margin; _currShift = currShift; @@ -945,7 +949,7 @@ bool KernCollider::mergeSlot(Segment *seg, Slot *slot, const Position &currShift const float sx = slot->origin().x + currShift.x; float x = (sx + (rtl > 0 ? bb.tr.x : bb.bl.x)) * rtl; // this isn't going to reduce _mingap so skip - if (x < rtl * (_xbound - _mingap - currSpace)) + if (_hit && x < rtl * (_xbound - _mingap - currSpace)) return false; const float sy = slot->origin().y + currShift.y; @@ -954,19 +958,24 @@ bool KernCollider::mergeSlot(Segment *seg, Slot *slot, const Position &currShift if (smin > smax) return false; bool collides = false; + bool nooverlap = true; for (int i = smin; i <= smax; ++i) { - float t; float here = _edges[i] * rtl; - float y = (float)(_miny - 1 + (i + .5f) * _sliceWidth); // vertical center of slice - if ( (x > here - _mingap - currSpace) ) + if (here > (float)9e37) + continue; + if (!_hit || x > here - _mingap - currSpace) { + float y = (float)(_miny - 1 + (i + .5f) * _sliceWidth); // vertical center of slice // 2 * currSpace to account for the space that is already separating them and the space we want to add float m = get_edge(seg, slot, currShift, y, _sliceWidth, 0., rtl > 0) * rtl + 2 * currSpace; - t = here - m; + if (m < (float)-8e37) // only true if the glyph has a gap in it + continue; + nooverlap = false; + float t = here - m; // _mingap is positive to shrink - if (t < _mingap) + if (t < _mingap || (!_hit && !collides)) { _mingap = t; collides = true; @@ -980,8 +989,14 @@ bool KernCollider::mergeSlot(Segment *seg, Slot *slot, const Position &currShift } #endif } + else + nooverlap = false; } - return collides; // note that true is not a necessarily reliable value + if (nooverlap) + _mingap = max(_mingap, _xbound + currSpace + _margin - x); + if (collides && !nooverlap) + _hit = true; + return collides | nooverlap; // note that true is not a necessarily reliable value } // end of KernCollider::mergeSlot diff --git a/Build/source/libs/graphite2/graphite2-src/src/Decompressor.cpp b/Build/source/libs/graphite2/graphite2-src/src/Decompressor.cpp index 4b8b1b4958d..26a4291392c 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/Decompressor.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/Decompressor.cpp @@ -43,29 +43,32 @@ u32 read_literal(u8 const * &s, u8 const * const e, u32 l) { return l; } -bool read_sequence(u8 const * &src, u8 const * const end, u8 const * &literal, u32 & literal_len, u32 & match_len, u32 & match_dist) +bool read_sequence(u8 const * &src, u8 const * const end, u8 const * &literal, + u32 & literal_len, u32 & match_len, u32 & match_dist) { u8 const token = *src++; literal_len = read_literal(src, end, token >> 4); literal = src; src += literal_len; - - if (src > end - 2 || src < literal) + + // Normal exit for end of stream, wrap arround check and parital match check. + if (src > end - sizeof(u16) || src < literal) return false; match_dist = *src++; match_dist |= *src++ << 8; - match_len = read_literal(src, end, token & 0xf); - - return src <= end-5; + match_len = read_literal(src, end, token & 0xf) + MINMATCH; + + // Malformed stream check. + return src <= end-MINCODA; } } int lz4::decompress(void const *in, size_t in_size, void *out, size_t out_size) { - if (out_size <= in_size || in_size < sizeof(unsigned long)+1) + if (out_size <= in_size || in_size < MINSRCSIZE) return -1; u8 const * src = static_cast(in), @@ -74,39 +77,47 @@ int lz4::decompress(void const *in, size_t in_size, void *out, size_t out_size) u8 * dst = static_cast(out), * const dst_end = dst + out_size; - + + // Check the in and out size hasn't wrapped around. + if (src >= src_end || dst >= dst_end) + return -1; + u32 literal_len = 0, match_len = 0, match_dist = 0; - - while (read_sequence(src, src_end, literal, literal_len, match_len, match_dist)) + + while (read_sequence(src, src_end, literal, literal_len, match_len, + match_dist)) { if (literal_len != 0) { - // Copy in literal. At this point the last full sequence must be at - // least MINMATCH + 5 from the end of the output buffer. - if (align(literal_len) > unsigned(dst_end - dst - (MINMATCH+5)) || dst_end - dst < MINMATCH + 5) + // Copy in literal. At this point the a minimal literal + minminal + // match plus the coda (1 + 2 + 5) must be 8 bytes or more allowing + // us to remain within the src buffer for an overrun_copy on + // machines upto 64 bits. + if (align(literal_len) > out_size) return -1; dst = overrun_copy(dst, literal, literal_len); + out_size -= literal_len; } // Copy, possibly repeating, match from earlier in the // decoded output. u8 const * const pcpy = dst - match_dist; if (pcpy < static_cast(out) - || pcpy >= dst - || match_len > unsigned(dst_end - dst - (MINMATCH+5)) - || dst_end - dst < MINMATCH + 5) + || match_len > unsigned(out_size - LASTLITERALS) + // Wrap around checks: + || out_size < LASTLITERALS || pcpy >= dst) return -1; - if (dst > pcpy+sizeof(unsigned long) - && dst + align(match_len + MINMATCH) <= dst_end) - dst = overrun_copy(dst, pcpy, match_len + MINMATCH); - else - dst = safe_copy(dst, pcpy, match_len + MINMATCH); + if (dst > pcpy+sizeof(unsigned long) + && align(match_len) <= out_size) + dst = overrun_copy(dst, pcpy, match_len); + else + dst = safe_copy(dst, pcpy, match_len); + out_size -= match_len; } - - if (literal_len > src_end - literal - || literal_len > dst_end - dst) + + if (literal > src_end - literal_len || literal_len > out_size) return -1; dst = fast_copy(dst, literal, literal_len); diff --git a/Build/source/libs/graphite2/graphite2-src/src/FeatureMap.cpp b/Build/source/libs/graphite2/graphite2-src/src/FeatureMap.cpp index d0fc55ddf50..87ebc39e23d 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/FeatureMap.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/FeatureMap.cpp @@ -73,7 +73,7 @@ FeatureRef::FeatureRef(const Face & face, unsigned short & bits_offset, uint32 max_val, uint32 name, uint16 uiName, uint16 flags, FeatureSetting *settings, uint16 num_set) throw() -: m_pFace(&face), +: m_face(face), m_nameValues(settings), m_mask(mask_over_val(max_val)), m_max(max_val), @@ -120,7 +120,7 @@ bool FeatureMap::readFeats(const Face & face) return false; } - m_feats = new FeatureRef [m_numFeats]; + m_feats = grzeroalloc(m_numFeats); uint16 * const defVals = gralloc(m_numFeats); if (!defVals || !m_feats) return false; unsigned short bits = 0; //to cause overflow on first Feature @@ -176,9 +176,9 @@ bool FeatureMap::readFeats(const Face & face) for (int i = 0; i < m_numFeats; ++i) { m_feats[i].applyValToFeature(defVals[i], m_defaultFeatures); - m_pNamedFeats[i] = m_feats+i; + m_pNamedFeats[i] = m_feats[i]; } - + free(defVals); qsort(m_pNamedFeats, m_numFeats, sizeof(NameAndFeatureRef), &cmpNameAndFeatures); @@ -267,13 +267,13 @@ const FeatureRef *FeatureMap::findFeatureRef(uint32 name) const } bool FeatureRef::applyValToFeature(uint32 val, Features & pDest) const -{ - if (val>maxVal() || !m_pFace) +{ + if (val>maxVal()) return false; if (pDest.m_pMap==NULL) - pDest.m_pMap = &m_pFace->theSill().theFeatureMap(); + pDest.m_pMap = &m_face.theSill().theFeatureMap(); else - if (pDest.m_pMap!=&m_pFace->theSill().theFeatureMap()) + if (pDest.m_pMap!=&m_face.theSill().theFeatureMap()) return false; //incompatible if (m_index >= pDest.size()) pDest.resize(m_index+1); @@ -283,11 +283,9 @@ bool FeatureRef::applyValToFeature(uint32 val, Features & pDest) const } uint32 FeatureRef::getFeatureVal(const Features& feats) const -{ - if (m_index < feats.size() && &m_pFace->theSill().theFeatureMap()==feats.m_pMap) - return (feats[m_index] & m_mask) >> m_bits; +{ + if (m_index < feats.size() && &m_face.theSill().theFeatureMap()==feats.m_pMap) + return (feats[m_index] & m_mask) >> m_bits; else return 0; } - - diff --git a/Build/source/libs/graphite2/graphite2-src/src/FileFace.cpp b/Build/source/libs/graphite2/graphite2-src/src/FileFace.cpp index d1510d3e9e8..b99e678b8fa 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/FileFace.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/FileFace.cpp @@ -92,7 +92,7 @@ const void *FileFace::get_table_fn(const void* appFaceHandle, unsigned int name, return 0; tbl = malloc(tbl_len); - if (fread(tbl, 1, tbl_len, file_face._file) != tbl_len) + if (!tbl || fread(tbl, 1, tbl_len, file_face._file) != tbl_len) { free(tbl); return 0; diff --git a/Build/source/libs/graphite2/graphite2-src/src/Pass.cpp b/Build/source/libs/graphite2/graphite2-src/src/Pass.cpp index 683143c5097..7dd4f1c9c96 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/Pass.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/Pass.cpp @@ -171,7 +171,9 @@ bool Pass::readPass(const byte * const pass_start, size_t pass_length, size_t su const uint16 * const o_actions = reinterpret_cast(p); be::skip(p, m_numRules + 1); const byte * const states = p; - if (e.test(2u*m_numTransition*m_numColumns >= (unsigned)(pass_end - p), E_BADPASSLENGTH)) return face.error(e); + if (e.test(2u*m_numTransition*m_numColumns >= (unsigned)(pass_end - p), E_BADPASSLENGTH) + || e.test(p >= pass_end, E_BADPASSLENGTH)) + return face.error(e); be::skip(p, m_numTransition*m_numColumns); be::skip(p); if (e.test(p != pcCode, E_BADPASSCCODEPTR)) return face.error(e); @@ -270,10 +272,11 @@ bool Pass::readRules(const byte * rule_map, const size_t num_entries, return face.error(e); } - byte * moved_progs = static_cast(realloc(m_progs, prog_pool_free - m_progs)); + byte * const moved_progs = prog_pool_free > m_progs ? static_cast(realloc(m_progs, prog_pool_free - m_progs)) : 0; if (e.test(!moved_progs, E_OUTOFMEM)) { - if (prog_pool_free - m_progs == 0) m_progs = 0; + free(m_progs); + m_progs = 0; return face.error(e); } @@ -714,18 +717,18 @@ void Pass::adjustSlot(int delta, Slot * & slot_out, SlotMap & smap) const { while (++delta <= 0 && slot_out) { + slot_out = slot_out->prev(); if (smap.highpassed() && smap.highwater() == slot_out) smap.highpassed(false); - slot_out = slot_out->prev(); } } else if (delta > 0) { while (--delta >= 0 && slot_out) { - slot_out = slot_out->next(); if (slot_out == smap.highwater() && slot_out) smap.highpassed(true); + slot_out = slot_out->next(); } } } @@ -968,8 +971,8 @@ bool Pass::resolveCollisions(Segment *seg, Slot *slotFix, Slot *start, if (nbor != slotFix // don't process if this is the slot of interest && !(cNbor->ignore()) // don't process if ignoring && (nbor == base || sameCluster // process if in the same cluster as slotFix - || !inKernCluster(seg, nbor) // or this cluster is not to be kerned - || (rtl ^ ignoreForKern)) // or it comes before(ltr) or after(rtl) + || !inKernCluster(seg, nbor)) // or this cluster is not to be kerned +// || (rtl ^ ignoreForKern)) // or it comes before(ltr) or after(rtl) && (!isRev // if processing forwards then good to merge otherwise only: || !(cNbor->flags() & SlotCollision::COLL_FIX) // merge in immovable stuff || ((cNbor->flags() & SlotCollision::COLL_KERN) && !sameCluster) // ignore other kernable clusters @@ -1037,6 +1040,8 @@ float Pass::resolveKern(Segment *seg, Slot *slotFix, GR_MAYBE_UNUSED Slot *start base = base->attachedTo(); SlotCollision *cFix = seg->collisionInfo(base); const GlyphCache &gc = seg->getFace()->glyphs(); + const Rect &bbb = seg->theGlyphBBoxTemporary(slotFix->gid()); + const float by = slotFix->origin().y + cFix->shift().y; if (base != slotFix) { @@ -1047,6 +1052,8 @@ float Pass::resolveKern(Segment *seg, Slot *slotFix, GR_MAYBE_UNUSED Slot *start bool isInit = false; KernCollider coll(dbgout); + ymax = max(by + bbb.tr.y, ymax); + ymin = min(by + bbb.bl.y, ymin); for (nbor = slotFix->next(); nbor; nbor = nbor->next()) { if (nbor->isChildOf(base)) @@ -1066,9 +1073,6 @@ float Pass::resolveKern(Segment *seg, Slot *slotFix, GR_MAYBE_UNUSED Slot *start else { space_count = 0; - float y = nbor->origin().y + cNbor->shift().y; - ymax = max(y + bb.tr.y, ymax); - ymin = min(y + bb.bl.y, ymin); if (nbor != slotFix && !cNbor->ignore()) { seenEnd = true; diff --git a/Build/source/libs/graphite2/graphite2-src/src/SegCacheEntry.cpp b/Build/source/libs/graphite2/graphite2-src/src/SegCacheEntry.cpp index d35912d5aed..70c561b62c5 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/SegCacheEntry.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/SegCacheEntry.cpp @@ -42,7 +42,7 @@ SegCacheEntry::SegCacheEntry(const uint16* cmapGlyphs, size_t length, Segment * m_accessCount(0), m_lastAccess(cacheTime) { if (m_unicode) - for (uint16 i = 0; i < length; i++) + for (size_t i = 0; i < length; i++) m_unicode[i] = cmapGlyphs[i]; const size_t glyphCount = seg->slotCount(), diff --git a/Build/source/libs/graphite2/graphite2-src/src/Segment.cpp b/Build/source/libs/graphite2/graphite2-src/src/Segment.cpp index 3020bfd36d0..f84d28cca8c 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/Segment.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/Segment.cpp @@ -59,7 +59,9 @@ Segment::Segment(unsigned int numchars, const Face* face, uint32 script, int tex m_dir(textDir), m_flags(((m_silf->flags() & 0x20) != 0) << 1) { - freeSlot(newSlot()); + Slot *s = newSlot(); + if (s) + freeSlot(s); m_bufSize = log_binary(numchars)+1; } diff --git a/Build/source/libs/graphite2/graphite2-src/src/Silf.cpp b/Build/source/libs/graphite2/graphite2-src/src/Silf.cpp index e36b50289f0..1848e020269 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/Silf.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/Silf.cpp @@ -276,6 +276,7 @@ size_t Silf::readClassMap(const byte *p, size_t data_len, uint32 version, Error return ERROROFFSET; // Check the linear offsets are sane, these must be monotonically increasing. + assert(m_nClass >= m_nLinear); for (const uint32 *o = m_classOffsets, * const o_end = o + m_nLinear; o != o_end; ++o) if (e.test(o[0] > o[1], E_BADCLASSOFFSET)) return ERROROFFSET; diff --git a/Build/source/libs/graphite2/graphite2-src/src/TtfUtil.cpp b/Build/source/libs/graphite2/graphite2-src/src/TtfUtil.cpp index 75e8da11c45..4fb73f2409f 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/TtfUtil.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/TtfUtil.cpp @@ -341,6 +341,11 @@ bool CheckTable(const Tag TableId, const void * pTable, size_t lTableSize) return be::swap(pName->format) == 0; } + case Tag::glyf: + { + return (lTableSize >= sizeof(Sfnt::Glyph)); + } + default: break; } @@ -464,7 +469,7 @@ void HeadTableModifyTime(const void * pHead, { const Sfnt::FontHeader * pTable = reinterpret_cast(pHead); - + ; *pnDateBC = be::swap(pTable->modified[0]); *pnDateAD = be::swap(pTable->modified[1]); } @@ -1247,7 +1252,7 @@ size_t LocaLookup(gid16 nGlyphId, void * GlyfLookup(const void * pGlyf, size_t nGlyfOffset, size_t nTableLen) { const uint8 * pByte = reinterpret_cast(pGlyf); - if (nGlyfOffset + pByte < pByte || nGlyfOffset + sizeof(Sfnt::Glyph) >= nTableLen) + if (nGlyfOffset + pByte < pByte || nGlyfOffset >= nTableLen - sizeof(Sfnt::Glyph)) return NULL; return const_cast(pByte + nGlyfOffset); } diff --git a/Build/source/libs/graphite2/graphite2-src/src/gr_face.cpp b/Build/source/libs/graphite2/graphite2-src/src/gr_face.cpp index fe1eb838207..65a4b117f5b 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/gr_face.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/gr_face.cpp @@ -195,7 +195,7 @@ gr_uint32 gr_face_lang_by_index(const gr_face* pFace, gr_uint16 i) void gr_face_destroy(gr_face *face) { - delete face; + delete static_cast(face); } diff --git a/Build/source/libs/graphite2/graphite2-src/src/gr_features.cpp b/Build/source/libs/graphite2/graphite2-src/src/gr_features.cpp index 38cebb7b5db..30c5c1099b6 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/gr_features.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/gr_features.cpp @@ -80,14 +80,14 @@ gr_int16 gr_fref_value(const gr_feature_ref* pfeatureref, gr_uint16 settingno) void* gr_fref_label(const gr_feature_ref* pfeatureref, gr_uint16 *langId, gr_encform utf, gr_uint32 *length) { - if(!pfeatureref || !pfeatureref->getFace()) + if(!pfeatureref) { langId = 0; length = 0; return NULL; } uint16 label = pfeatureref->getNameId(); - NameTable * names = pfeatureref->getFace()->nameTable(); + NameTable * names = pfeatureref->getFace().nameTable(); if (!names) { langId = 0; @@ -101,14 +101,14 @@ void* gr_fref_label(const gr_feature_ref* pfeatureref, gr_uint16 *langId, gr_enc void* gr_fref_value_label(const gr_feature_ref*pfeatureref, gr_uint16 setting, gr_uint16 *langId, gr_encform utf, gr_uint32 *length) { - if(!pfeatureref || (setting >= pfeatureref->getNumSettings()) || !pfeatureref->getFace()) + if(!pfeatureref || (setting >= pfeatureref->getNumSettings())) { langId = 0; length = 0; return NULL; } uint16 label = pfeatureref->getSettingName(setting); - NameTable * names = pfeatureref->getFace()->nameTable(); + NameTable * names = pfeatureref->getFace().nameTable(); if (!names) { langId = 0; @@ -131,7 +131,7 @@ gr_feature_val* gr_featureval_clone(const gr_feature_val* pfeatures/*may be NULL void gr_featureval_destroy(gr_feature_val *p) { - delete p; + delete static_cast(p); } diff --git a/Build/source/libs/graphite2/graphite2-src/src/gr_font.cpp b/Build/source/libs/graphite2/graphite2-src/src/gr_font.cpp index ed70ab7381e..7470e1bb5f1 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/gr_font.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/gr_font.cpp @@ -47,10 +47,16 @@ gr_font* gr_make_font(float ppm/*pixels per em*/, const gr_face *face) gr_font* gr_make_font_with_ops(float ppm/*pixels per em*/, const void* appFontHandle/*non-NULL*/, const gr_font_ops * font_ops, const gr_face * face/*needed for scaling*/) { //the appFontHandle must stay alive all the time when the gr_font is alive. When finished with the gr_font, call destroy_gr_font - if (face == 0) return 0; + if (face == 0 || ppm <= 0) return 0; Font * const res = new Font(ppm, *face, appFontHandle, font_ops); - return static_cast(res); + if (*res) + return static_cast(res); + else + { + delete res; + return 0; + } } gr_font* gr_make_font_with_advance_fn(float ppm/*pixels per em*/, const void* appFontHandle/*non-NULL*/, gr_advance_fn getAdvance, const gr_face * face/*needed for scaling*/) @@ -61,7 +67,7 @@ gr_font* gr_make_font_with_advance_fn(float ppm/*pixels per em*/, const void* ap void gr_font_destroy(gr_font *font) { - delete font; + delete static_cast(font); } diff --git a/Build/source/libs/graphite2/graphite2-src/src/gr_logging.cpp b/Build/source/libs/graphite2/graphite2-src/src/gr_logging.cpp index 3e453ba8e2c..94efc453bb8 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/gr_logging.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/gr_logging.cpp @@ -41,7 +41,7 @@ of the License or (at your option) any later version. using namespace graphite2; #if !defined GRAPHITE2_NTRACING -json *global_log = NULL; +json *global_log = 0; #endif extern "C" { @@ -120,6 +120,7 @@ void gr_stop_logging(GR_MAYBE_UNUSED gr_face * face) { FILE * log = global_log->stream(); delete global_log; + global_log = 0; fclose(log); } #endif @@ -214,7 +215,7 @@ json & graphite2::operator << (json & j, const dslot & ds) throw() j << "user" << json::flat << json::array; for (int n = 0; n!= seg.numAttrs(); ++n) j << s.userAttrs()[n]; - j << json::close; + j << json::close; if (s.firstChild()) { j << "children" << json::flat << json::array; diff --git a/Build/source/libs/graphite2/graphite2-src/src/gr_segment.cpp b/Build/source/libs/graphite2/graphite2-src/src/gr_segment.cpp index 0ab7a0854cc..37ce7ddd0ec 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/gr_segment.cpp +++ b/Build/source/libs/graphite2/graphite2-src/src/gr_segment.cpp @@ -103,7 +103,7 @@ gr_segment* gr_make_seg(const gr_font *font, const gr_face *face, gr_uint32 scri if (pFeats == 0) pFeats = tmp_feats = static_cast(face->theSill().cloneFeatures(0)); gr_segment * seg = makeAndInitialize(font, face, script, pFeats, enc, pStart, nChars, dir); - delete tmp_feats; + delete static_cast(tmp_feats); return seg; } @@ -111,7 +111,7 @@ gr_segment* gr_make_seg(const gr_font *font, const gr_face *face, gr_uint32 scri void gr_seg_destroy(gr_segment* p) { - delete p; + delete static_cast(p); } diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Code.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Code.h index 3985ae416e9..3439299e3d6 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Code.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Code.h @@ -162,7 +162,7 @@ inline void Machine::Code::externalProgramMoved(ptrdiff_t dist) throw() { if (_code && !_own) { - _code += dist / sizeof(instr); + _code += dist / signed(sizeof(instr)); _data += dist; } } diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Collider.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Collider.h index 5d953b4a4cb..267776dd4e9 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Collider.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Collider.h @@ -210,6 +210,7 @@ private: float _sliceWidth; // width of each slice float _mingap; float _xbound; // max or min edge + bool _hit; #if !defined GRAPHITE2_NTRACING // Debugging @@ -233,7 +234,8 @@ KernCollider::KernCollider(GR_MAYBE_UNUSED json *dbg) _maxy(1e38f), _sliceWidth(0.0f), _mingap(0.0f), - _xbound(0.0) + _xbound(0.0), + _hit(false) { #if !defined GRAPHITE2_NTRACING _seg = 0; diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Compression.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Compression.h index 61351c416ea..6596af2ffa4 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Compression.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Compression.h @@ -47,7 +47,10 @@ typedef uint32_t u32; typedef uint64_t u64; #endif -ptrdiff_t const MINMATCH = 4; +ptrdiff_t const MINMATCH = 4, + LASTLITERALS = 5, + MINCODA = LASTLITERALS+1, + MINSRCSIZE = 13; template inline diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/FeatureMap.h b/Build/source/libs/graphite2/graphite2-src/src/inc/FeatureMap.h index fc845f6e165..9610c39a487 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/FeatureMap.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/FeatureMap.h @@ -56,7 +56,6 @@ class FeatureRef static const uint8 SIZEOF_CHUNK = sizeof(chunk_t)*8; public: - FeatureRef(); FeatureRef(const Face & face, unsigned short & bits_offset, uint32 max_val, uint32 name, uint16 uiName, uint16 flags, FeatureSetting *settings, uint16 num_set) throw(); @@ -76,14 +75,14 @@ public: uint16 getSettingName(uint16 index) const { return m_nameValues[index].label(); } int16 getSettingValue(uint16 index) const { return m_nameValues[index].value(); } uint32 maxVal() const { return m_max; } - const Face* getFace() const { return m_pFace;} + const Face & getFace() const { return m_face;} const FeatureMap* getFeatureMap() const;// { return m_pFace;} CLASS_NEW_DELETE; private: FeatureRef(const FeatureRef & rhs); - const Face * m_pFace; //not NULL + const Face & m_face; FeatureSetting * m_nameValues; // array of name table ids for feature values chunk_t m_mask, // bit mask to get the value from the vector m_max; // max value the value can take @@ -99,27 +98,18 @@ private: //unimplemented }; -inline -FeatureRef::FeatureRef() -: m_pFace(0), m_nameValues(0), - m_mask(0), m_max(0), m_id(0), - m_nameid(0), m_flags(0), m_numSet(0), - m_bits(0), m_index(0) -{ -} - class NameAndFeatureRef { public: NameAndFeatureRef(uint32 name = 0) : m_name(name) , m_pFRef(NULL){} - NameAndFeatureRef(const FeatureRef* p/*not NULL*/) : m_name(p->getId()), m_pFRef(p) {} + NameAndFeatureRef(FeatureRef const & p) : m_name(p.getId()), m_pFRef(&p) {} bool operator<(const NameAndFeatureRef& rhs) const //orders by m_name { return m_name #include +#include "Main.h" namespace graphite2 { @@ -104,7 +105,9 @@ void Vector::reserve(size_t n) if (n > capacity()) { const ptrdiff_t sz = size(); - m_first = static_cast(realloc(m_first, n*sizeof(T))); + size_t requested; + if (checked_mul(n,sizeof(T), requested)) std::abort(); + m_first = static_cast(realloc(m_first, requested)); if (!m_first) std::abort(); m_last = m_first + sz; m_end = m_first + n; diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Machine.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Machine.h index 1a01b7a43f7..b23819fb981 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Machine.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Machine.h @@ -15,8 +15,8 @@ You should also have received a copy of the GNU Lesser General Public License along with this library in the file named "LICENSE". - If not, write to the Free Software Foundation, 51 Franklin Street, - Suite 500, Boston, MA 02110-1335, USA or visit their web page on the + If not, write to the Free Software Foundation, 51 Franklin Street, + Suite 500, Boston, MA 02110-1335, USA or visit their web page on the internet at http://www.fsf.org/licenses/lgpl.html. Alternatively, the contents of this file may be used under the terms of the @@ -27,11 +27,12 @@ of the License or (at your option) any later version. // This general interpreter interface. // Author: Tim Eves -// Build one of direct_machine.cpp or call_machine.cpp to implement this +// Build one of direct_machine.cpp or call_machine.cpp to implement this // interface. #pragma once #include +#include #include #include "inc/Main.h" @@ -56,6 +57,13 @@ of the License or (at your option) any later version. #define REGPARM(n) #endif +#if defined(__MINGW32__) +// MinGW's at some point includes winnt.h which #define's a +// DELETE macro, which conflicts with enum opcode below, so we undefine +// it here. +#undef DELETE +#endif + namespace graphite2 { // Forward declarations @@ -64,7 +72,7 @@ class Slot; class SlotMap; -namespace vm +namespace vm { @@ -112,12 +120,12 @@ enum opcode { PUT_GLYPH, PUSH_GLYPH_ATTR, PUSH_ATT_TO_GLYPH_ATTR, BITOR, BITAND, BITNOT, BITSET, SET_FEAT, - MAX_OPCODE, + MAX_OPCODE, // private opcodes for internal use only, comes after all other on disk opcodes TEMP_COPY = MAX_OPCODE }; -struct opcode_t +struct opcode_t { instr impl[2]; uint8 param_sz; @@ -186,6 +194,8 @@ inline Machine::status_t Machine::status() const throw() inline void Machine::check_final_stack(const stack_t * const sp) { + if (_status != finished) return; + stack_t const * const base = _stack + STACK_GUARD, * const limit = base + STACK_MAX; if (sp < base) _status = stack_underflow; // This should be impossible now. @@ -195,6 +205,3 @@ inline void Machine::check_final_stack(const stack_t * const sp) } // namespace vm } // namespace graphite2 - - - diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Main.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Main.h index deeffcccd5a..f66b48d0b7d 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Main.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Main.h @@ -15,8 +15,8 @@ You should also have received a copy of the GNU Lesser General Public License along with this library in the file named "LICENSE". - If not, write to the Free Software Foundation, 51 Franklin Street, - Suite 500, Boston, MA 02110-1335, USA or visit their web page on the + If not, write to the Free Software Foundation, 51 Franklin Street, + Suite 500, Boston, MA 02110-1335, USA or visit their web page on the internet at http://www.fsf.org/licenses/lgpl.html. Alternatively, the contents of this file may be used under the terms of the @@ -77,15 +77,61 @@ public: struct telemetry {}; #endif +// Checked multiplaction to catch overflow or underflow when allocating memory +#if defined(__has_builtin) + #if __has_builtin(__builtin_mul_overflow) + #define HAVE_BUILTIN_OVERFLOW + #endif +#elif defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__INTEL_COMPILER) + #define HAVE_BUILTIN_OVERFLOW +#endif +#if defined(__has_include) + #if __has_include() + #define HAVE_INTSAFE_H + #endif +#elif defined(_WIN32) + #define HAVE_INTSAFE_H +#endif + +// Need to import intsafe into the top level namespace +#if defined(HAVE_INTSAFE_H) +} // namespace graphite2 + +#include + +namespace graphite2 { +#endif + +#if defined(HAVE_BUILTIN_OVERFLOW) +inline +bool checked_mul(const size_t a, const size_t b, size_t & t) { + return __builtin_mul_overflow(a, b, &t); +} +#elif defined(HAVE_INTSAFE_H) +inline +bool checked_mul(const size_t a, const size_t b, size_t & t) { + return SizeTMult(a, b, &t) == INTSAFE_E_ARITHMETIC_OVERFLOW; +} +#else +inline +bool checked_mul(const size_t a, const size_t b, size_t & t) { + t = a*b; + return (((a | b) & (~size_t(0) << (sizeof(size_t) << 2))) && (t / a != b)); +} +#endif + // typesafe wrapper around malloc for simple types // use free(pointer) to deallocate template T * gralloc(size_t n) { + size_t total; + if (checked_mul(n, sizeof(T), total)) + return 0; #ifdef GRAPHITE2_TELEMETRY - telemetry::count_bytes(sizeof(T) * n); + telemetry::count_bytes(total); #endif - return static_cast(malloc(sizeof(T) * n)); + return static_cast(malloc(total)); } template T * grzeroalloc(size_t n) @@ -128,7 +174,7 @@ inline T max(const T a, const T b) #if defined(__clang__) && __cplusplus >= 201103L /* clang's fallthrough annotations are only available starting in C++11. */ - #define GR_FALLTHROUGH [[clang::fallthrough]] + #define GR_FALLTHROUGH [[fallthrough]] #elif defined(_MSC_VER) /* * MSVC's __fallthrough annotations are checked by /analyze (Code Analysis): @@ -136,6 +182,8 @@ inline T max(const T a, const T b) */ #include #define GR_FALLTHROUGH __fallthrough +#elif __GNUC__ >= 7 + #define GR_FALLTHROUGH __attribute__ ((fallthrough)) #else #define GR_FALLTHROUGH /* fallthrough */ #endif diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Segment.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Segment.h index bcba1f2a87b..e5a8ad408a7 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Segment.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Segment.h @@ -205,7 +205,7 @@ int8 Segment::getSlotBidiClass(Slot *s) const inline void Segment::finalise(const Font *font, bool reverse) { - if (!m_first) return; + if (!m_first || !m_last) return; m_advance = positionSlots(font, m_first, m_last, m_silf->dir(), true); //associateChars(0, m_numCharinfo); diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Sparse.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Sparse.h index 4a8e3fa7d1f..ceb9cea6f39 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Sparse.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Sparse.h @@ -15,8 +15,8 @@ You should also have received a copy of the GNU Lesser General Public License along with this library in the file named "LICENSE". - If not, write to the Free Software Foundation, 51 Franklin Street, - Suite 500, Boston, MA 02110-1335, USA or visit their web page on the + If not, write to the Free Software Foundation, 51 Franklin Street, + Suite 500, Boston, MA 02110-1335, USA or visit their web page on the internet at http://www.fsf.org/licenses/lgpl.html. Alternatively, the contents of this file may be used under the terms of the @@ -73,7 +73,7 @@ public: size_t size() const throw(); size_t _sizeof() const throw(); - + CLASS_NEW_DELETE; private: @@ -122,10 +122,7 @@ sparse::sparse(I attr, const I last) + n_values); if (m_array.values == 0) - { - free(m_array.values); m_array.map=0; return; - } // coverity[forward_null : FALSE] Since m_array is union and m_array.values is not NULL chunk * ci = m_array.map; diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/opcode_table.h b/Build/source/libs/graphite2/graphite2-src/src/inc/opcode_table.h index 50ae1d4d077..0191088b220 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/opcode_table.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/opcode_table.h @@ -73,7 +73,7 @@ static const opcode_t opcode_table[] = {{do2(gtr_eq)}, 0, "GTR_EQ"}, // 0x18 {{do_(next), NILOP}, 0, "NEXT"}, - {{do_(next_n), NILOP}, 1, "NEXT_N"}, // number <= smap.end - map + {{NILOP, NILOP}, 1, "NEXT_N"}, // number <= smap.end - map {{do_(next), NILOP}, 0, "COPY_NEXT"}, {{do_(put_glyph_8bit_obs), NILOP}, 1, "PUT_GLYPH_8BIT_OBS"}, // output_class {{do_(put_subs_8bit_obs), NILOP}, 3, "PUT_SUBS_8BIT_OBS"}, // slot input_class output_class diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/opcodes.h b/Build/source/libs/graphite2/graphite2-src/src/inc/opcodes.h index 3b6dd3fc3d8..0064a3e678f 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/opcodes.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/opcodes.h @@ -26,7 +26,7 @@ of the License or (at your option) any later version. */ #pragma once // This file will be pulled into and integrated into a machine implmentation -// DO NOT build directly and under no circumstances every #include headers in +// DO NOT build directly and under no circumstances ever #include headers in // here or you will break the direct_machine. // // Implementers' notes @@ -65,7 +65,7 @@ of the License or (at your option) any later version. // #define NOT_IMPLEMENTED assert(false) -#define NOT_IMPLEMENTED +// #define NOT_IMPLEMENTED #define binop(op) const uint32 a = pop(); *sp = uint32(*sp) op a #define sbinop(op) const int32 a = pop(); *sp = int32(*sp) op a @@ -130,8 +130,10 @@ STARTOP(mul) ENDOP STARTOP(div_) - if (*sp == 0) DIE; - sbinop(/); + const int32 b = pop(); + const int32 a = int32(*sp); + if (b == 0 || (a == std::numeric_limits::min() && b == -1)) DIE; + *sp = int32(*sp) / b; ENDOP STARTOP(min_) @@ -208,12 +210,12 @@ STARTOP(next) ++map; ENDOP -STARTOP(next_n) - use_params(1); - NOT_IMPLEMENTED; +//STARTOP(next_n) +// use_params(1); +// NOT_IMPLEMENTED; //declare_params(1); //const size_t num = uint8(*param); -ENDOP +//ENDOP //STARTOP(copy_next) // if (is) is = is->next(); @@ -337,6 +339,7 @@ STARTOP(delete_) else seg.last(is->prev()); + if (is == smap.highwater()) smap.highwater(is->next()); if (is->prev()) diff --git a/Build/source/libs/graphite2/version.ac b/Build/source/libs/graphite2/version.ac index 531b0dde9d4..c8a7aa10a6b 100644 --- a/Build/source/libs/graphite2/version.ac +++ b/Build/source/libs/graphite2/version.ac @@ -8,4 +8,4 @@ dnl dnl -------------------------------------------------------- dnl dnl m4-include this file to define the current graphite2 version -m4_define([graphite2_version], [1.3.10]) +m4_define([graphite2_version], [1.3.11]) -- cgit v1.2.3