| 76 | } |
| 77 | |
| 78 | void CFESetFontData(CommodettoFontEngine bmf, const void *fontData, uint32_t fontDataSize) |
| 79 | { |
| 80 | if (fontData == bmf->fontData) |
| 81 | return; // unchanged |
| 82 | |
| 83 | bmf->charCount = 0; // zero in case of failure |
| 84 | if (fontDataSize < 9) |
| 85 | return; |
| 86 | |
| 87 | const unsigned char *start = fontData; |
| 88 | const unsigned char *bytes = start; |
| 89 | const unsigned char *end = start + fontDataSize; |
| 90 | |
| 91 | uint8_t version = c_read8(bytes + 3); |
| 92 | if ((0x42 != c_read8(bytes + 0)) || (0x4D != c_read8(bytes + 1)) || (0x46 != c_read8(bytes + 2)) || ((3 != version) && (4 != version))) |
| 93 | return; |
| 94 | bmf->isCompressed = 4 == version; |
| 95 | |
| 96 | bytes += 4; |
| 97 | |
| 98 | // skip block 1 |
| 99 | if (1 != c_read8(bytes)) |
| 100 | return; |
| 101 | bytes += 1; |
| 102 | |
| 103 | uint32_t size = c_read32(bytes); |
| 104 | if (size > (uint32_t)((end - bytes) - 4)) |
| 105 | return; |
| 106 | bytes += 4 + size; |
| 107 | |
| 108 | // get lineHeight from block 2 |
| 109 | if (((end - bytes) < 5) || (2 != c_read8(bytes))) |
| 110 | return; |
| 111 | bytes += 1; |
| 112 | |
| 113 | size = c_read32(bytes); |
| 114 | bytes += 4; |
| 115 | if (((end - bytes) < 10) || (size < 8) || (size > (uint32_t)(end - bytes))) |
| 116 | return; |
| 117 | |
| 118 | bmf->height = c_read16(bytes); |
| 119 | bmf->ascent = c_read16(bytes + 2); |
| 120 | if (1 != c_read16(bytes + 8)) // pages |
| 121 | return; |
| 122 | |
| 123 | bytes += size; |
| 124 | |
| 125 | // skip block 3 |
| 126 | if (((end - bytes) < 5) || (3 != c_read8(bytes))) |
| 127 | return; |
| 128 | bytes += 1; |
| 129 | |
| 130 | size = c_read32(bytes); |
| 131 | if (size > (uint32_t)((end - bytes) - 4)) |
| 132 | return; |
| 133 | bytes += 4 + size; |
| 134 | |
| 135 | // use block 4 |
no outgoing calls
no test coverage detected