Skip to content

Commit

Permalink
Allow empty charsets in cff::parse_charset.
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV authored May 24, 2024
1 parent 423f97d commit dabe8a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/tables/cff/cff1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ impl<'a> Table<'a> {
Some(charset_id::EXPERT_SUBSET) => Charset::ExpertSubset,
Some(offset) => {
let mut s = Stream::new_at(data, offset)?;
parse_charset(number_of_glyphs.get(), &mut s)?
parse_charset(number_of_glyphs, &mut s)?
}
None => Charset::ISOAdobe, // default
};
Expand Down
16 changes: 8 additions & 8 deletions src/tables/cff/charset.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::StringId;
use crate::parser::{FromData, LazyArray16, Stream};
use crate::GlyphId;
use core::num::NonZeroU16;

/// The Expert Encoding conversion as defined in the Adobe Technical Note #5176 Appendix C.
#[rustfmt::skip]
Expand Down Expand Up @@ -189,24 +190,23 @@ impl Charset<'_> {
}
}

pub(crate) fn parse_charset<'a>(number_of_glyphs: u16, s: &mut Stream<'a>) -> Option<Charset<'a>> {
if number_of_glyphs < 2 {
return None;
}

pub(crate) fn parse_charset<'a>(
number_of_glyphs: NonZeroU16,
s: &mut Stream<'a>,
) -> Option<Charset<'a>> {
// -1 everywhere, since `.notdef` is omitted.
let format = s.read::<u8>()?;
match format {
0 => Some(Charset::Format0(
s.read_array16::<StringId>(number_of_glyphs - 1)?,
s.read_array16::<StringId>(number_of_glyphs.get() - 1)?,
)),
1 => {
// The number of ranges is not defined, so we have to
// read until no glyphs are left.
let mut count = 0;
{
let mut s = s.clone();
let mut total_left = number_of_glyphs - 1;
let mut total_left = number_of_glyphs.get() - 1;
while total_left > 0 {
s.skip::<StringId>(); // first
let left = s.read::<u8>()?;
Expand All @@ -222,7 +222,7 @@ pub(crate) fn parse_charset<'a>(number_of_glyphs: u16, s: &mut Stream<'a>) -> Op
let mut count = 0;
{
let mut s = s.clone();
let mut total_left = number_of_glyphs - 1;
let mut total_left = number_of_glyphs.get() - 1;
while total_left > 0 {
s.skip::<StringId>(); // first
let left = s.read::<u16>()?.checked_add(1)?;
Expand Down

0 comments on commit dabe8a5

Please sign in to comment.