Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.5K input consumes 8Gb of RAM #161

Closed
kcc opened this issue Nov 5, 2015 · 10 comments
Closed

1.5K input consumes 8Gb of RAM #161

kcc opened this issue Nov 5, 2015 · 10 comments

Comments

@kcc
Copy link
Collaborator

kcc commented Nov 5, 2015

found by libFuzzer, see #139

Feed the attached input to the fuzzer target function, observe it consume 8Gb RAM.
crash-3511ff5c1647150595846ac414c595cccac34f18.pdf

Huge allocations seem to be coming from here:

    #10 0x4e9a07 in hb_buffer_t::enlarge(unsigned int) src/hb-buffer.cc:110:37
    #11 0x4ed70a in hb_buffer_t::ensure(unsigned int) src/./hb-buffer-private.hh:206:56
    #12 0x4ed70a in hb_buffer_t::make_room_for(unsigned int, unsigned int) src/hb-buffer.cc:134
    #13 0x4ed70a in hb_buffer_t::output_glyph(unsigned int) src/hb-buffer.cc:342
    #14 0x653ba4 in OT::Sequence::apply(OT::hb_apply_context_t*) const src/./hb-ot-layout-gsub-table.hh:291:7
    #15 0x6524c8 in OT::MultipleSubstFormat1::apply(OT::hb_apply_context_t*) const src/./hb-ot-layout-gsub-table.hh:360:5
    #16 0x6524c8 in bool OT::hb_apply_context_t::dispatch<OT::MultipleSubstFormat1>(OT::MultipleSubstFormat1 const&) src/./hb-ot-layout-gsubgpos-private.hh:446
    #17 0x6524c8 in OT::hb_apply_context_t::return_t OT::MultipleSubst::dispatch<OT::hb_apply_context_t>(OT::hb_apply_context_t*) const src/./hb-ot-layout-gsub-table.hh:423
    #18 0x6524c8 in OT::hb_apply_context_t::return_t OT::SubstLookupSubTable::dispatch<OT::hb_apply_context_t>(OT::hb_apply_context_t*, unsigned int) const src/./hb-ot-layout-gsub-table.hh:1080
    #19 0x5ecc79 in OT::hb_apply_context_t::return_t OT::Lookup::dispatch<OT::SubstLookupSubTable, OT::hb_apply_context_t>(OT::hb_apply_context_t*) const src/./hb-ot-layout-common-private.hh:625:»
    #20 0x5ecc79 in OT::hb_apply_context_t::return_t OT::SubstLookup::dispatch<OT::hb_apply_context_t>(OT::hb_apply_context_t*) const src/./hb-ot-layout-gsub-table.hh:1234
    #21 0x5ecc79 in OT::SubstLookup::apply(OT::hb_apply_context_t*) const src/./hb-ot-layout-gsub-table.hh:1127
    #22 0x5ecc79 in _ZL13apply_forwardIN2OT11SubstLookupEEbPNS0_18hb_apply_context_tERKT_RK33hb_ot_layout_lookup_accelerator_t src/hb-ot-layout.cc:898
    #23 0x5ecc79 in _ZL12apply_stringI9GSUBProxyEvPN2OT18hb_apply_context_tERKNT_6LookupERK33hb_ot_layout_lookup_accelerator_t src/hb-ot-layout.cc:976
    #24 0x5fcb93 in void hb_ot_map_t::apply<GSUBProxy>(GSUBProxy const&, hb_ot_shape_plan_t const*, hb_font_t*, hb_buffer_t*) const src/hb-ot-layout.cc:1027:7
    #25 0x5ebe43 in hb_ot_map_t::substitute(hb_ot_shape_plan_t const*, hb_font_t*, hb_buffer_t*) const src/hb-ot-layout.cc:1043:3
    #26 0x53f13d in hb_ot_shape_plan_t::substitute(hb_font_t*, hb_buffer_t*) const src/./hb-ot-shape-private.hh:59:73
    #27 0x53f13d in hb_ot_substitute_complex(hb_ot_shape_context_t*) src/hb-ot-shape.cc:588
    #28 0x53f13d in hb_ot_substitute(hb_ot_shape_context_t*) src/hb-ot-shape.cc:602
    #29 0x53f13d in hb_ot_shape_internal(hb_ot_shape_context_t*) src/hb-ot-shape.cc:818
    #30 0x53f13d in _hb_ot_shape src/hb-ot-shape.cc:839
    #31 0x522686 in hb_shape_plan_execute src/./hb-shaper-list.hh:43:1
    #32 0x51f986 in hb_shape_full src/hb-shape.cc:375:19
    #33 0x51f986 in hb_shape src/hb-shape.cc:405
@behdad
Copy link
Member

behdad commented Nov 5, 2015

Yeah, exponential growth in buffer is well-known. Can happen in much shorter fonts even. See eg:
https://github.com/behdad/harfbuzz-hazmat

We have to put an artificial limit in. Something like 16x the starting length...

@jfkthame WDYT? Is there any need for that number to be configurable?

@jfkthame
Copy link
Collaborator

jfkthame commented Nov 5, 2015

I doubt it needs to be configurable, but you might as well use a #define that could be overridden if someone really wants to (or just for testing purposes)....

#ifndef HB_BUFFER_MAX_EXPANSION_FACTOR
#define HB_BUFFER_MAX_EXPANSION_FACTOR 32
#endif

(Picking 32 as default on the grounds that compatibility decomps in Unicode can stretch to at least 18 characters -- U+FDFA is the longest one I can think of offhand. It seems unlikely anyone would really want to do that in a 'ccmp' feature or w/e, but we can claim that it'd at least be possible.)

@behdad
Copy link
Member

behdad commented Nov 5, 2015

Good point. 32 it is then. I'll try to implement this soon.

@behdad
Copy link
Member

behdad commented Nov 6, 2015

I'm going to make the rule be inputlen * HB_BUFFER_MAX_EXPANSION_FACTOR + 8192 just to make it impossible to hit the condition for real-world use-cases, while still catching abusive ones.

behdad added a commit that referenced this issue Nov 6, 2015
@behdad behdad closed this as completed in f0599db Nov 6, 2015
@behdad
Copy link
Member

behdad commented Nov 6, 2015

After limiting memory expansion, I also fixed a hang...

I added more -D stuff to hb/test/fuzzing/Makefile.am, specifically:

+       -DHB_BUFFER_MAX_EXPANSION_FACTOR=3 \
+       -DHB_BUFFER_MAX_LEN_MIN=8 \

behdad added a commit that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
fanc999 pushed a commit to fanc999/harfbuzz that referenced this issue Nov 6, 2015
simoncozens pushed a commit to simoncozens/harfbuzz that referenced this issue Nov 6, 2015
simoncozens pushed a commit to simoncozens/harfbuzz that referenced this issue Nov 6, 2015
simoncozens pushed a commit to simoncozens/harfbuzz that referenced this issue Nov 6, 2015
@kcc
Copy link
Collaborator Author

kcc commented Nov 6, 2015

Now the fuzzer crashes like this (see #157 (comment)):

harfbuzz_asan_cov_fuzzer: hb-buffer.cc:398: bool hb_buffer_t::move_to(unsigned int): Assertion `i <= out_len + (len - idx)' failed.

@behdad
Copy link
Member

behdad commented Nov 7, 2015

Thanks. We never tested the OOM codepaths. We are now. Guess I'll postpone a release until next week so I can sort these out.

behdad added a commit that referenced this issue Nov 19, 2015
Fixes assert fail in #161
with libharfbuzz-fuzzing.
@behdad
Copy link
Member

behdad commented Nov 19, 2015

Now the fuzzer crashes like this (see #157 (comment)):

harfbuzz_asan_cov_fuzzer: hb-buffer.cc:398: bool hb_buffer_t::move_to(unsigned int): Assertion `i <= out_len + (len - idx)' failed.

Should be fixed.

@kcc
Copy link
Collaborator Author

kcc commented Nov 19, 2015

Confirmed, fuzzing restarted, it's running at nice 4000 exec/s

@behdad
Copy link
Member

behdad commented Nov 19, 2015

Excellent! I finally go ahead and make that overdue release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants