File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
Userland/Libraries/LibPDF Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,8 @@ PDFErrorOr<ByteBuffer> Filter::decode_ascii_hex(ReadonlyBytes bytes)
94
94
95
95
PDFErrorOr<ByteBuffer> Filter::decode_ascii85 (ReadonlyBytes bytes)
96
96
{
97
+ // 3.3.2 ASCII85Decode Filter
98
+
97
99
ByteBuffer buffer;
98
100
TRY (buffer.try_ensure_capacity (bytes.size ()));
99
101
@@ -114,10 +116,21 @@ PDFErrorOr<ByteBuffer> Filter::decode_ascii85(ReadonlyBytes bytes)
114
116
115
117
u32 number = 0 ;
116
118
117
- auto const to_write = byte_index + 5 >= bytes.size () ? bytes.size () - byte_index : 5 ;
119
+ auto to_write = byte_index + 5 >= bytes.size () ? bytes.size () - byte_index : 5 ;
120
+
121
+ Optional<u32 > end_of_data_index {};
118
122
119
123
for (int i = 0 ; i < 5 ; i++) {
120
- auto byte = byte_index >= bytes.size () ? ' u' : bytes[byte_index++];
124
+ // We check for the EOD sequence '~>', but as '~' can only appear in
125
+ // this sequence, there is no need to check for '>'.
126
+ if (!end_of_data_index.has_value () && bytes[byte_index] == ' ~' ) {
127
+ end_of_data_index = i;
128
+ to_write = i + 1 ;
129
+ }
130
+
131
+ bool const should_fake_end = byte_index >= bytes.size () || end_of_data_index.has_value ();
132
+ auto const byte = should_fake_end ? ' u' : bytes[byte_index++];
133
+
121
134
if (Reader::is_whitespace (byte)) {
122
135
i--;
123
136
continue ;
@@ -127,6 +140,9 @@ PDFErrorOr<ByteBuffer> Filter::decode_ascii85(ReadonlyBytes bytes)
127
140
128
141
for (size_t i = 0 ; i < to_write - 1 ; i++)
129
142
buffer.append (reinterpret_cast <u8 *>(&number)[3 - i]);
143
+
144
+ if (end_of_data_index.has_value ())
145
+ break ;
130
146
}
131
147
132
148
return buffer;
You can’t perform that action at this time.
0 commit comments