File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -620,21 +620,23 @@ impl StreamingDecoder {
620
620
}
621
621
622
622
if local_table {
623
- let entries = PLTE_CHANNELS * ( 1 << ( table_size + 1 ) ) ;
624
- let mut pal = Vec :: new ( ) ;
625
- pal. try_reserve_exact ( entries) . map_err ( |_| io:: ErrorKind :: OutOfMemory ) ?;
626
- frame. palette = Some ( pal) ;
627
- goto ! ( LocalPalette ( entries) )
623
+ let pal_len = PLTE_CHANNELS * ( 1 << ( table_size + 1 ) ) ;
624
+ frame. palette . get_or_insert_with ( Vec :: new)
625
+ . try_reserve_exact ( pal_len) . map_err ( |_| io:: ErrorKind :: OutOfMemory ) ?;
626
+ goto ! ( LocalPalette ( pal_len) )
628
627
} else {
629
628
goto ! ( LocalPalette ( 0 ) )
630
629
}
631
630
}
632
631
}
633
632
}
634
633
GlobalPalette ( left) => {
635
- let n = cmp :: min ( left , buf . len ( ) ) ;
634
+ // the global_color_table is guaranteed to have the exact capacity required
636
635
if left > 0 {
637
- self . global_color_table . extend_from_slice ( & buf[ ..n] ) ;
636
+ let n = cmp:: min ( left, buf. len ( ) ) ;
637
+ if n <= self . global_color_table . capacity ( ) - self . global_color_table . len ( ) {
638
+ self . global_color_table . extend_from_slice ( & buf[ ..n] ) ;
639
+ }
638
640
goto ! ( n, GlobalPalette ( left - n) )
639
641
} else {
640
642
goto ! ( BlockStart ( b) , emit Decoded :: GlobalPalette (
You can’t perform that action at this time.
0 commit comments