Commit 0f0502b13ff6a6eb2ee98de6d2835326df75a168
Committed by
m-holger
1 parent
843e2b45
Add trailing underscore to QPDFParser member variables
Co-authored-by: m-holger <34626170+m-holger@users.noreply.github.com>
Showing
2 changed files
with
166 additions
and
165 deletions
libqpdf/QPDFParser.cc
| ... | ... | @@ -185,13 +185,13 @@ QPDFParser::parse_first(bool content_stream) |
| 185 | 185 | // effect of reading the object and changing the file pointer. If you do this, it will cause a |
| 186 | 186 | // logic error to be thrown from QPDF::inParse(). |
| 187 | 187 | |
| 188 | - QPDF::Doc::ParseGuard pg(context); | |
| 189 | - start = input.tell(); | |
| 190 | - if (!tokenizer.nextToken(input, object_description)) { | |
| 191 | - warn(tokenizer.getErrorMessage()); | |
| 188 | + QPDF::Doc::ParseGuard pg(context_); | |
| 189 | + start_ = input_.tell(); | |
| 190 | + if (!tokenizer_.nextToken(input_, object_description_)) { | |
| 191 | + warn(tokenizer_.getErrorMessage()); | |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - switch (tokenizer.getType()) { | |
| 194 | + switch (tokenizer_.getType()) { | |
| 195 | 195 | case QPDFTokenizer::tt_eof: |
| 196 | 196 | if (content_stream) { |
| 197 | 197 | // In content stream mode, leave object uninitialized to indicate EOF |
| ... | ... | @@ -219,31 +219,31 @@ QPDFParser::parse_first(bool content_stream) |
| 219 | 219 | |
| 220 | 220 | case QPDFTokenizer::tt_array_open: |
| 221 | 221 | case QPDFTokenizer::tt_dict_open: |
| 222 | - stack.clear(); | |
| 223 | - stack.emplace_back( | |
| 224 | - input, | |
| 225 | - (tokenizer.getType() == QPDFTokenizer::tt_array_open) ? st_array : st_dictionary_key); | |
| 226 | - frame = &stack.back(); | |
| 222 | + stack_.clear(); | |
| 223 | + stack_.emplace_back( | |
| 224 | + input_, | |
| 225 | + (tokenizer_.getType() == QPDFTokenizer::tt_array_open) ? st_array : st_dictionary_key); | |
| 226 | + frame_ = &stack_.back(); | |
| 227 | 227 | return parseRemainder(content_stream); |
| 228 | 228 | |
| 229 | 229 | case QPDFTokenizer::tt_bool: |
| 230 | - return withDescription<QPDF_Bool>(tokenizer.getValue() == "true"); | |
| 230 | + return withDescription<QPDF_Bool>(tokenizer_.getValue() == "true"); | |
| 231 | 231 | |
| 232 | 232 | case QPDFTokenizer::tt_null: |
| 233 | 233 | return {QPDFObject::create<QPDF_Null>()}; |
| 234 | 234 | |
| 235 | 235 | case QPDFTokenizer::tt_integer: |
| 236 | - return withDescription<QPDF_Integer>(QUtil::string_to_ll(tokenizer.getValue().c_str())); | |
| 236 | + return withDescription<QPDF_Integer>(QUtil::string_to_ll(tokenizer_.getValue().c_str())); | |
| 237 | 237 | |
| 238 | 238 | case QPDFTokenizer::tt_real: |
| 239 | - return withDescription<QPDF_Real>(tokenizer.getValue()); | |
| 239 | + return withDescription<QPDF_Real>(tokenizer_.getValue()); | |
| 240 | 240 | |
| 241 | 241 | case QPDFTokenizer::tt_name: |
| 242 | - return withDescription<QPDF_Name>(tokenizer.getValue()); | |
| 242 | + return withDescription<QPDF_Name>(tokenizer_.getValue()); | |
| 243 | 243 | |
| 244 | 244 | case QPDFTokenizer::tt_word: |
| 245 | 245 | { |
| 246 | - auto const& value = tokenizer.getValue(); | |
| 246 | + auto const& value = tokenizer_.getValue(); | |
| 247 | 247 | if (content_stream) { |
| 248 | 248 | return withDescription<QPDF_Operator>(value); |
| 249 | 249 | } else if (value == "endobj") { |
| ... | ... | @@ -252,7 +252,7 @@ QPDFParser::parse_first(bool content_stream) |
| 252 | 252 | // Adobe Reader appears to ignore them. Treat this as a null and do not move the |
| 253 | 253 | // input source's offset. |
| 254 | 254 | empty_ = true; |
| 255 | - input.seek(input.getLastOffset(), SEEK_SET); | |
| 255 | + input_.seek(input_.getLastOffset(), SEEK_SET); | |
| 256 | 256 | if (!content_stream) { |
| 257 | 257 | warn("empty object treated as null"); |
| 258 | 258 | } |
| ... | ... | @@ -264,12 +264,12 @@ QPDFParser::parse_first(bool content_stream) |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | case QPDFTokenizer::tt_string: |
| 267 | - if (decrypter) { | |
| 268 | - std::string s{tokenizer.getValue()}; | |
| 269 | - decrypter->decryptString(s); | |
| 267 | + if (decrypter_) { | |
| 268 | + std::string s{tokenizer_.getValue()}; | |
| 269 | + decrypter_->decryptString(s); | |
| 270 | 270 | return withDescription<QPDF_String>(s); |
| 271 | 271 | } else { |
| 272 | - return withDescription<QPDF_String>(tokenizer.getValue()); | |
| 272 | + return withDescription<QPDF_String>(tokenizer_.getValue()); | |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | default: |
| ... | ... | @@ -286,58 +286,58 @@ QPDFParser::parseRemainder(bool content_stream) |
| 286 | 286 | // effect of reading the object and changing the file pointer. If you do this, it will cause a |
| 287 | 287 | // logic error to be thrown from QPDF::inParse(). |
| 288 | 288 | |
| 289 | - bad_count = 0; | |
| 289 | + bad_count_ = 0; | |
| 290 | 290 | bool b_contents = false; |
| 291 | 291 | |
| 292 | 292 | while (true) { |
| 293 | - if (!tokenizer.nextToken(input, object_description)) { | |
| 294 | - warn(tokenizer.getErrorMessage()); | |
| 293 | + if (!tokenizer_.nextToken(input_, object_description_)) { | |
| 294 | + warn(tokenizer_.getErrorMessage()); | |
| 295 | 295 | } |
| 296 | - ++good_count; // optimistically | |
| 296 | + ++good_count_; // optimistically | |
| 297 | 297 | |
| 298 | - if (int_count != 0) { | |
| 298 | + if (int_count_ != 0) { | |
| 299 | 299 | // Special handling of indirect references. Treat integer tokens as part of an indirect |
| 300 | 300 | // reference until proven otherwise. |
| 301 | - if (tokenizer.getType() == QPDFTokenizer::tt_integer) { | |
| 302 | - if (++int_count > 2) { | |
| 301 | + if (tokenizer_.getType() == QPDFTokenizer::tt_integer) { | |
| 302 | + if (++int_count_ > 2) { | |
| 303 | 303 | // Process the oldest buffered integer. |
| 304 | - addInt(int_count); | |
| 304 | + addInt(int_count_); | |
| 305 | 305 | } |
| 306 | - last_offset_buffer[int_count % 2] = input.getLastOffset(); | |
| 307 | - int_buffer[int_count % 2] = QUtil::string_to_ll(tokenizer.getValue().c_str()); | |
| 306 | + last_offset_buffer_[int_count_ % 2] = input_.getLastOffset(); | |
| 307 | + int_buffer_[int_count_ % 2] = QUtil::string_to_ll(tokenizer_.getValue().c_str()); | |
| 308 | 308 | continue; |
| 309 | 309 | |
| 310 | 310 | } else if ( |
| 311 | - int_count >= 2 && tokenizer.getType() == QPDFTokenizer::tt_word && | |
| 312 | - tokenizer.getValue() == "R") { | |
| 313 | - if (!context) { | |
| 311 | + int_count_ >= 2 && tokenizer_.getType() == QPDFTokenizer::tt_word && | |
| 312 | + tokenizer_.getValue() == "R") { | |
| 313 | + if (!context_) { | |
| 314 | 314 | throw std::logic_error( |
| 315 | 315 | "QPDFParser::parse called without context on an object with indirect " |
| 316 | 316 | "references"); |
| 317 | 317 | } |
| 318 | - auto id = QIntC::to_int(int_buffer[(int_count - 1) % 2]); | |
| 319 | - auto gen = QIntC::to_int(int_buffer[(int_count) % 2]); | |
| 318 | + auto id = QIntC::to_int(int_buffer_[(int_count_ - 1) % 2]); | |
| 319 | + auto gen = QIntC::to_int(int_buffer_[(int_count_) % 2]); | |
| 320 | 320 | if (!(id < 1 || gen < 0 || gen >= 65535)) { |
| 321 | - add(ParseGuard::getObject(context, id, gen, parse_pdf)); | |
| 321 | + add(ParseGuard::getObject(context_, id, gen, parse_pdf_)); | |
| 322 | 322 | } else { |
| 323 | 323 | add_bad_null( |
| 324 | 324 | "treating bad indirect reference (" + std::to_string(id) + " " + |
| 325 | 325 | std::to_string(gen) + " R) as null"); |
| 326 | 326 | } |
| 327 | - int_count = 0; | |
| 327 | + int_count_ = 0; | |
| 328 | 328 | continue; |
| 329 | 329 | |
| 330 | - } else if (int_count > 0) { | |
| 330 | + } else if (int_count_ > 0) { | |
| 331 | 331 | // Process the buffered integers before processing the current token. |
| 332 | - if (int_count > 1) { | |
| 333 | - addInt(int_count - 1); | |
| 332 | + if (int_count_ > 1) { | |
| 333 | + addInt(int_count_ - 1); | |
| 334 | 334 | } |
| 335 | - addInt(int_count); | |
| 336 | - int_count = 0; | |
| 335 | + addInt(int_count_); | |
| 336 | + int_count_ = 0; | |
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - switch (tokenizer.getType()) { | |
| 340 | + switch (tokenizer_.getType()) { | |
| 341 | 341 | case QPDFTokenizer::tt_eof: |
| 342 | 342 | warn("parse error while reading object"); |
| 343 | 343 | if (content_stream) { |
| ... | ... | @@ -358,23 +358,23 @@ QPDFParser::parseRemainder(bool content_stream) |
| 358 | 358 | continue; |
| 359 | 359 | |
| 360 | 360 | case QPDFTokenizer::tt_array_close: |
| 361 | - if (frame->state == st_array) { | |
| 362 | - auto object = frame->null_count > 100 | |
| 363 | - ? QPDFObject::create<QPDF_Array>(std::move(frame->olist), true) | |
| 364 | - : QPDFObject::create<QPDF_Array>(std::move(frame->olist)); | |
| 365 | - setDescription(object, frame->offset - 1); | |
| 361 | + if (frame_->state == st_array) { | |
| 362 | + auto object = frame_->null_count > 100 | |
| 363 | + ? QPDFObject::create<QPDF_Array>(std::move(frame_->olist), true) | |
| 364 | + : QPDFObject::create<QPDF_Array>(std::move(frame_->olist)); | |
| 365 | + setDescription(object, frame_->offset - 1); | |
| 366 | 366 | // The `offset` points to the next of "[". Set the rewind offset to point to the |
| 367 | 367 | // beginning of "[". This has been explicitly tested with whitespace surrounding the |
| 368 | 368 | // array start delimiter. getLastOffset points to the array end token and therefore |
| 369 | 369 | // can't be used here. |
| 370 | - if (stack.size() <= 1) { | |
| 370 | + if (stack_.size() <= 1) { | |
| 371 | 371 | return object; |
| 372 | 372 | } |
| 373 | - stack.pop_back(); | |
| 374 | - frame = &stack.back(); | |
| 373 | + stack_.pop_back(); | |
| 374 | + frame_ = &stack_.back(); | |
| 375 | 375 | add(std::move(object)); |
| 376 | 376 | } else { |
| 377 | - if (sanity_checks) { | |
| 377 | + if (sanity_checks_) { | |
| 378 | 378 | // During sanity checks, assume nesting of containers is corrupt and object is |
| 379 | 379 | // unusable. |
| 380 | 380 | warn("unexpected array close token; giving up on reading object"); |
| ... | ... | @@ -385,46 +385,46 @@ QPDFParser::parseRemainder(bool content_stream) |
| 385 | 385 | continue; |
| 386 | 386 | |
| 387 | 387 | case QPDFTokenizer::tt_dict_close: |
| 388 | - if (frame->state <= st_dictionary_value) { | |
| 388 | + if (frame_->state <= st_dictionary_value) { | |
| 389 | 389 | // Attempt to recover more or less gracefully from invalid dictionaries. |
| 390 | - auto& dict = frame->dict; | |
| 390 | + auto& dict = frame_->dict; | |
| 391 | 391 | |
| 392 | - if (frame->state == st_dictionary_value) { | |
| 392 | + if (frame_->state == st_dictionary_value) { | |
| 393 | 393 | warn( |
| 394 | - frame->offset, | |
| 394 | + frame_->offset, | |
| 395 | 395 | "dictionary ended prematurely; using null as value for last key"); |
| 396 | - dict[frame->key] = QPDFObject::create<QPDF_Null>(); | |
| 396 | + dict[frame_->key] = QPDFObject::create<QPDF_Null>(); | |
| 397 | 397 | } |
| 398 | - if (!frame->olist.empty()) { | |
| 399 | - if (sanity_checks) { | |
| 398 | + if (!frame_->olist.empty()) { | |
| 399 | + if (sanity_checks_) { | |
| 400 | 400 | warn( |
| 401 | - frame->offset, | |
| 401 | + frame_->offset, | |
| 402 | 402 | "expected dictionary keys but found non-name objects; ignoring"); |
| 403 | 403 | } else { |
| 404 | 404 | fixMissingKeys(); |
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | - if (!frame->contents_string.empty() && dict.contains("/Type") && | |
| 408 | + if (!frame_->contents_string.empty() && dict.contains("/Type") && | |
| 409 | 409 | dict["/Type"].isNameAndEquals("/Sig") && dict.contains("/ByteRange") && |
| 410 | 410 | dict.contains("/Contents") && dict["/Contents"].isString()) { |
| 411 | - dict["/Contents"] = QPDFObjectHandle::newString(frame->contents_string); | |
| 412 | - dict["/Contents"].setParsedOffset(frame->contents_offset); | |
| 411 | + dict["/Contents"] = QPDFObjectHandle::newString(frame_->contents_string); | |
| 412 | + dict["/Contents"].setParsedOffset(frame_->contents_offset); | |
| 413 | 413 | } |
| 414 | 414 | auto object = QPDFObject::create<QPDF_Dictionary>(std::move(dict)); |
| 415 | - setDescription(object, frame->offset - 2); | |
| 415 | + setDescription(object, frame_->offset - 2); | |
| 416 | 416 | // The `offset` points to the next of "<<". Set the rewind offset to point to the |
| 417 | 417 | // beginning of "<<". This has been explicitly tested with whitespace surrounding |
| 418 | 418 | // the dictionary start delimiter. getLastOffset points to the dictionary end token |
| 419 | 419 | // and therefore can't be used here. |
| 420 | - if (stack.size() <= 1) { | |
| 420 | + if (stack_.size() <= 1) { | |
| 421 | 421 | return object; |
| 422 | 422 | } |
| 423 | - stack.pop_back(); | |
| 424 | - frame = &stack.back(); | |
| 423 | + stack_.pop_back(); | |
| 424 | + frame_ = &stack_.back(); | |
| 425 | 425 | add(std::move(object)); |
| 426 | 426 | } else { |
| 427 | - if (sanity_checks) { | |
| 427 | + if (sanity_checks_) { | |
| 428 | 428 | // During sanity checks, assume nesting of containers is corrupt and object is |
| 429 | 429 | // unusable. |
| 430 | 430 | warn("unexpected dictionary close token; giving up on reading object"); |
| ... | ... | @@ -436,20 +436,20 @@ QPDFParser::parseRemainder(bool content_stream) |
| 436 | 436 | |
| 437 | 437 | case QPDFTokenizer::tt_array_open: |
| 438 | 438 | case QPDFTokenizer::tt_dict_open: |
| 439 | - if (stack.size() > max_nesting) { | |
| 439 | + if (stack_.size() > max_nesting) { | |
| 440 | 440 | limits_error( |
| 441 | 441 | "parser-max-nesting", "ignoring excessively deeply nested data structure"); |
| 442 | 442 | } |
| 443 | 443 | b_contents = false; |
| 444 | - stack.emplace_back( | |
| 445 | - input, | |
| 446 | - (tokenizer.getType() == QPDFTokenizer::tt_array_open) ? st_array | |
| 447 | - : st_dictionary_key); | |
| 448 | - frame = &stack.back(); | |
| 444 | + stack_.emplace_back( | |
| 445 | + input_, | |
| 446 | + (tokenizer_.getType() == QPDFTokenizer::tt_array_open) ? st_array | |
| 447 | + : st_dictionary_key); | |
| 448 | + frame_ = &stack_.back(); | |
| 449 | 449 | continue; |
| 450 | 450 | |
| 451 | 451 | case QPDFTokenizer::tt_bool: |
| 452 | - addScalar<QPDF_Bool>(tokenizer.getValue() == "true"); | |
| 452 | + addScalar<QPDF_Bool>(tokenizer_.getValue() == "true"); | |
| 453 | 453 | continue; |
| 454 | 454 | |
| 455 | 455 | case QPDFTokenizer::tt_null: |
| ... | ... | @@ -459,37 +459,37 @@ QPDFParser::parseRemainder(bool content_stream) |
| 459 | 459 | case QPDFTokenizer::tt_integer: |
| 460 | 460 | if (!content_stream) { |
| 461 | 461 | // Buffer token in case it is part of an indirect reference. |
| 462 | - last_offset_buffer[1] = input.getLastOffset(); | |
| 463 | - int_buffer[1] = QUtil::string_to_ll(tokenizer.getValue().c_str()); | |
| 464 | - int_count = 1; | |
| 462 | + last_offset_buffer_[1] = input_.getLastOffset(); | |
| 463 | + int_buffer_[1] = QUtil::string_to_ll(tokenizer_.getValue().c_str()); | |
| 464 | + int_count_ = 1; | |
| 465 | 465 | } else { |
| 466 | - addScalar<QPDF_Integer>(QUtil::string_to_ll(tokenizer.getValue().c_str())); | |
| 466 | + addScalar<QPDF_Integer>(QUtil::string_to_ll(tokenizer_.getValue().c_str())); | |
| 467 | 467 | } |
| 468 | 468 | continue; |
| 469 | 469 | |
| 470 | 470 | case QPDFTokenizer::tt_real: |
| 471 | - addScalar<QPDF_Real>(tokenizer.getValue()); | |
| 471 | + addScalar<QPDF_Real>(tokenizer_.getValue()); | |
| 472 | 472 | continue; |
| 473 | 473 | |
| 474 | 474 | case QPDFTokenizer::tt_name: |
| 475 | - if (frame->state == st_dictionary_key) { | |
| 476 | - frame->key = tokenizer.getValue(); | |
| 477 | - frame->state = st_dictionary_value; | |
| 478 | - b_contents = decrypter && frame->key == "/Contents"; | |
| 475 | + if (frame_->state == st_dictionary_key) { | |
| 476 | + frame_->key = tokenizer_.getValue(); | |
| 477 | + frame_->state = st_dictionary_value; | |
| 478 | + b_contents = decrypter_ && frame_->key == "/Contents"; | |
| 479 | 479 | continue; |
| 480 | 480 | } else { |
| 481 | - addScalar<QPDF_Name>(tokenizer.getValue()); | |
| 481 | + addScalar<QPDF_Name>(tokenizer_.getValue()); | |
| 482 | 482 | } |
| 483 | 483 | continue; |
| 484 | 484 | |
| 485 | 485 | case QPDFTokenizer::tt_word: |
| 486 | 486 | if (content_stream) { |
| 487 | - addScalar<QPDF_Operator>(tokenizer.getValue()); | |
| 487 | + addScalar<QPDF_Operator>(tokenizer_.getValue()); | |
| 488 | 488 | continue; |
| 489 | 489 | } |
| 490 | 490 | |
| 491 | - if (sanity_checks) { | |
| 492 | - if (tokenizer.getValue() == "endobj" || tokenizer.getValue() == "endstream") { | |
| 491 | + if (sanity_checks_) { | |
| 492 | + if (tokenizer_.getValue() == "endobj" || tokenizer_.getValue() == "endstream") { | |
| 493 | 493 | // During sanity checks, assume an unexpected endobj or endstream indicates that |
| 494 | 494 | // we are parsing past the end of the object. |
| 495 | 495 | warn( |
| ... | ... | @@ -504,21 +504,21 @@ QPDFParser::parseRemainder(bool content_stream) |
| 504 | 504 | |
| 505 | 505 | warn("unknown token while reading object; treating as string"); |
| 506 | 506 | check_too_many_bad_tokens(); |
| 507 | - addScalar<QPDF_String>(tokenizer.getValue()); | |
| 507 | + addScalar<QPDF_String>(tokenizer_.getValue()); | |
| 508 | 508 | |
| 509 | 509 | continue; |
| 510 | 510 | |
| 511 | 511 | case QPDFTokenizer::tt_string: |
| 512 | 512 | { |
| 513 | - auto const& val = tokenizer.getValue(); | |
| 514 | - if (decrypter) { | |
| 513 | + auto const& val = tokenizer_.getValue(); | |
| 514 | + if (decrypter_) { | |
| 515 | 515 | if (b_contents) { |
| 516 | - frame->contents_string = val; | |
| 517 | - frame->contents_offset = input.getLastOffset(); | |
| 516 | + frame_->contents_string = val; | |
| 517 | + frame_->contents_offset = input_.getLastOffset(); | |
| 518 | 518 | b_contents = false; |
| 519 | 519 | } |
| 520 | 520 | std::string s{val}; |
| 521 | - decrypter->decryptString(s); | |
| 521 | + decrypter_->decryptString(s); | |
| 522 | 522 | addScalar<QPDF_String>(s); |
| 523 | 523 | } else { |
| 524 | 524 | addScalar<QPDF_String>(val); |
| ... | ... | @@ -535,15 +535,15 @@ QPDFParser::parseRemainder(bool content_stream) |
| 535 | 535 | void |
| 536 | 536 | QPDFParser::add(std::shared_ptr<QPDFObject>&& obj) |
| 537 | 537 | { |
| 538 | - if (frame->state != st_dictionary_value) { | |
| 538 | + if (frame_->state != st_dictionary_value) { | |
| 539 | 539 | // If state is st_dictionary_key then there is a missing key. Push onto olist for |
| 540 | 540 | // processing once the tt_dict_close token has been found. |
| 541 | - frame->olist.emplace_back(std::move(obj)); | |
| 541 | + frame_->olist.emplace_back(std::move(obj)); | |
| 542 | 542 | } else { |
| 543 | - if (auto res = frame->dict.insert_or_assign(frame->key, std::move(obj)); !res.second) { | |
| 543 | + if (auto res = frame_->dict.insert_or_assign(frame_->key, std::move(obj)); !res.second) { | |
| 544 | 544 | warnDuplicateKey(); |
| 545 | 545 | } |
| 546 | - frame->state = st_dictionary_key; | |
| 546 | + frame_->state = st_dictionary_key; | |
| 547 | 547 | } |
| 548 | 548 | } |
| 549 | 549 | |
| ... | ... | @@ -552,17 +552,17 @@ QPDFParser::addNull() |
| 552 | 552 | { |
| 553 | 553 | const static ObjectPtr null_obj = QPDFObject::create<QPDF_Null>(); |
| 554 | 554 | |
| 555 | - if (frame->state != st_dictionary_value) { | |
| 555 | + if (frame_->state != st_dictionary_value) { | |
| 556 | 556 | // If state is st_dictionary_key then there is a missing key. Push onto olist for |
| 557 | 557 | // processing once the tt_dict_close token has been found. |
| 558 | - frame->olist.emplace_back(null_obj); | |
| 558 | + frame_->olist.emplace_back(null_obj); | |
| 559 | 559 | } else { |
| 560 | - if (auto res = frame->dict.insert_or_assign(frame->key, null_obj); !res.second) { | |
| 560 | + if (auto res = frame_->dict.insert_or_assign(frame_->key, null_obj); !res.second) { | |
| 561 | 561 | warnDuplicateKey(); |
| 562 | 562 | } |
| 563 | - frame->state = st_dictionary_key; | |
| 563 | + frame_->state = st_dictionary_key; | |
| 564 | 564 | } |
| 565 | - ++frame->null_count; | |
| 565 | + ++frame_->null_count; | |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | void |
| ... | ... | @@ -576,8 +576,8 @@ QPDFParser::add_bad_null(std::string const& msg) |
| 576 | 576 | void |
| 577 | 577 | QPDFParser::addInt(int count) |
| 578 | 578 | { |
| 579 | - auto obj = QPDFObject::create<QPDF_Integer>(int_buffer[count % 2]); | |
| 580 | - obj->setDescription(context, description, last_offset_buffer[count % 2]); | |
| 579 | + auto obj = QPDFObject::create<QPDF_Integer>(int_buffer_[count % 2]); | |
| 580 | + obj->setDescription(context_, description_, last_offset_buffer_[count % 2]); | |
| 581 | 581 | add(std::move(obj)); |
| 582 | 582 | } |
| 583 | 583 | |
| ... | ... | @@ -585,15 +585,15 @@ template <typename T, typename... Args> |
| 585 | 585 | void |
| 586 | 586 | QPDFParser::addScalar(Args&&... args) |
| 587 | 587 | { |
| 588 | - auto limit = Limits::parser_max_container_size(bad_count || sanity_checks); | |
| 589 | - if (frame->olist.size() >= limit || frame->dict.size() >= limit) { | |
| 588 | + auto limit = Limits::parser_max_container_size(bad_count_ || sanity_checks_); | |
| 589 | + if (frame_->olist.size() >= limit || frame_->dict.size() >= limit) { | |
| 590 | 590 | // Stop adding scalars. We are going to abort when the close token or a bad token is |
| 591 | 591 | // encountered. |
| 592 | - max_bad_count = 1; | |
| 592 | + max_bad_count_ = 1; | |
| 593 | 593 | check_too_many_bad_tokens(); // always throws Error() |
| 594 | 594 | } |
| 595 | 595 | auto obj = QPDFObject::create<T>(std::forward<Args>(args)...); |
| 596 | - obj->setDescription(context, description, input.getLastOffset()); | |
| 596 | + obj->setDescription(context_, description_, input_.getLastOffset()); | |
| 597 | 597 | add(std::move(obj)); |
| 598 | 598 | } |
| 599 | 599 | |
| ... | ... | @@ -602,7 +602,7 @@ QPDFObjectHandle |
| 602 | 602 | QPDFParser::withDescription(Args&&... args) |
| 603 | 603 | { |
| 604 | 604 | auto obj = QPDFObject::create<T>(std::forward<Args>(args)...); |
| 605 | - obj->setDescription(context, description, start); | |
| 605 | + obj->setDescription(context_, description_, start_); | |
| 606 | 606 | return {obj}; |
| 607 | 607 | } |
| 608 | 608 | |
| ... | ... | @@ -610,7 +610,7 @@ void |
| 610 | 610 | QPDFParser::setDescription(ObjectPtr& obj, qpdf_offset_t parsed_offset) |
| 611 | 611 | { |
| 612 | 612 | if (obj) { |
| 613 | - obj->setDescription(context, description, parsed_offset); | |
| 613 | + obj->setDescription(context_, description_, parsed_offset); | |
| 614 | 614 | } |
| 615 | 615 | } |
| 616 | 616 | |
| ... | ... | @@ -618,22 +618,22 @@ void |
| 618 | 618 | QPDFParser::fixMissingKeys() |
| 619 | 619 | { |
| 620 | 620 | std::set<std::string> names; |
| 621 | - for (auto& obj: frame->olist) { | |
| 621 | + for (auto& obj: frame_->olist) { | |
| 622 | 622 | if (obj.raw_type_code() == ::ot_name) { |
| 623 | 623 | names.insert(obj.obj_sp()->getStringValue()); |
| 624 | 624 | } |
| 625 | 625 | } |
| 626 | 626 | int next_fake_key = 1; |
| 627 | - for (auto const& item: frame->olist) { | |
| 627 | + for (auto const& item: frame_->olist) { | |
| 628 | 628 | while (true) { |
| 629 | 629 | const std::string key = "/QPDFFake" + std::to_string(next_fake_key++); |
| 630 | - const bool found_fake = !frame->dict.contains(key) && !names.contains(key); | |
| 630 | + const bool found_fake = !frame_->dict.contains(key) && !names.contains(key); | |
| 631 | 631 | QTC::TC("qpdf", "QPDFParser found fake", (found_fake ? 0 : 1)); |
| 632 | 632 | if (found_fake) { |
| 633 | 633 | warn( |
| 634 | - frame->offset, | |
| 634 | + frame_->offset, | |
| 635 | 635 | "expected dictionary key but found non-name object; inserting key " + key); |
| 636 | - frame->dict[key] = item; | |
| 636 | + frame_->dict[key] = item; | |
| 637 | 637 | break; |
| 638 | 638 | } |
| 639 | 639 | } |
| ... | ... | @@ -643,9 +643,9 @@ QPDFParser::fixMissingKeys() |
| 643 | 643 | void |
| 644 | 644 | QPDFParser::check_too_many_bad_tokens() |
| 645 | 645 | { |
| 646 | - auto limit = Limits::parser_max_container_size(bad_count || sanity_checks); | |
| 647 | - if (frame->olist.size() >= limit || frame->dict.size() >= limit) { | |
| 648 | - if (bad_count) { | |
| 646 | + auto limit = Limits::parser_max_container_size(bad_count_ || sanity_checks_); | |
| 647 | + if (frame_->olist.size() >= limit || frame_->dict.size() >= limit) { | |
| 648 | + if (bad_count_) { | |
| 649 | 649 | limits_error( |
| 650 | 650 | "parser-max-container-size-damaged", |
| 651 | 651 | "encountered errors while parsing an array or dictionary with more than " + |
| ... | ... | @@ -656,23 +656,23 @@ QPDFParser::check_too_many_bad_tokens() |
| 656 | 656 | "encountered an array or dictionary with more than " + std::to_string(limit) + |
| 657 | 657 | " elements during xref recovery; giving up on reading object"); |
| 658 | 658 | } |
| 659 | - if (max_bad_count && --max_bad_count == 0) { | |
| 659 | + if (max_bad_count_ && --max_bad_count_ == 0) { | |
| 660 | 660 | limits_error( |
| 661 | 661 | "parser-max-errors", "too many errors during parsing; treating object as null"); |
| 662 | 662 | } |
| 663 | - if (good_count > 4) { | |
| 664 | - good_count = 0; | |
| 665 | - bad_count = 1; | |
| 663 | + if (good_count_ > 4) { | |
| 664 | + good_count_ = 0; | |
| 665 | + bad_count_ = 1; | |
| 666 | 666 | return; |
| 667 | 667 | } |
| 668 | - if (++bad_count > 5 || | |
| 669 | - (frame->state != st_array && std::cmp_less(max_bad_count, frame->olist.size()))) { | |
| 668 | + if (++bad_count_ > 5 || | |
| 669 | + (frame_->state != st_array && std::cmp_less(max_bad_count_, frame_->olist.size()))) { | |
| 670 | 670 | // Give up after 5 errors in close proximity or if the number of missing dictionary keys |
| 671 | 671 | // exceeds the remaining number of allowable total errors. |
| 672 | 672 | warn("too many errors; giving up on reading object"); |
| 673 | 673 | throw Error(); |
| 674 | 674 | } |
| 675 | - good_count = 0; | |
| 675 | + good_count_ = 0; | |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | void |
| ... | ... | @@ -689,8 +689,8 @@ QPDFParser::warn(QPDFExc const& e) const |
| 689 | 689 | // If parsing on behalf of a QPDF object and want to give a warning, we can warn through the |
| 690 | 690 | // object. If parsing for some other reason, such as an explicit creation of an object from a |
| 691 | 691 | // string, then just throw the exception. |
| 692 | - if (context) { | |
| 693 | - context->warn(e); | |
| 692 | + if (context_) { | |
| 693 | + context_->warn(e); | |
| 694 | 694 | } else { |
| 695 | 695 | throw e; |
| 696 | 696 | } |
| ... | ... | @@ -700,24 +700,25 @@ void |
| 700 | 700 | QPDFParser::warnDuplicateKey() |
| 701 | 701 | { |
| 702 | 702 | warn( |
| 703 | - frame->offset, | |
| 704 | - "dictionary has duplicated key " + frame->key + "; last occurrence overrides earlier ones"); | |
| 703 | + frame_->offset, | |
| 704 | + "dictionary has duplicated key " + frame_->key + | |
| 705 | + "; last occurrence overrides earlier ones"); | |
| 705 | 706 | } |
| 706 | 707 | |
| 707 | 708 | void |
| 708 | 709 | QPDFParser::warn(qpdf_offset_t offset, std::string const& msg) const |
| 709 | 710 | { |
| 710 | - if (stream_id) { | |
| 711 | - std::string descr = "object "s + std::to_string(obj_id) + " 0"; | |
| 712 | - std::string name = context->getFilename() + " object stream " + std::to_string(stream_id); | |
| 711 | + if (stream_id_) { | |
| 712 | + std::string descr = "object "s + std::to_string(obj_id_) + " 0"; | |
| 713 | + std::string name = context_->getFilename() + " object stream " + std::to_string(stream_id_); | |
| 713 | 714 | warn(QPDFExc(qpdf_e_damaged_pdf, name, descr, offset, msg)); |
| 714 | 715 | } else { |
| 715 | - warn(QPDFExc(qpdf_e_damaged_pdf, input.getName(), object_description, offset, msg)); | |
| 716 | + warn(QPDFExc(qpdf_e_damaged_pdf, input_.getName(), object_description_, offset, msg)); | |
| 716 | 717 | } |
| 717 | 718 | } |
| 718 | 719 | |
| 719 | 720 | void |
| 720 | 721 | QPDFParser::warn(std::string const& msg) const |
| 721 | 722 | { |
| 722 | - warn(input.getLastOffset(), msg); | |
| 723 | + warn(input_.getLastOffset(), msg); | |
| 723 | 724 | } | ... | ... |
libqpdf/qpdf/QPDFParser.hh
| ... | ... | @@ -77,16 +77,16 @@ class QPDFParser |
| 77 | 77 | int stream_id = 0, |
| 78 | 78 | int obj_id = 0, |
| 79 | 79 | bool sanity_checks = false) : |
| 80 | - input(input), | |
| 81 | - object_description(object_description), | |
| 82 | - tokenizer(tokenizer), | |
| 83 | - decrypter(decrypter), | |
| 84 | - context(context), | |
| 85 | - description(std::move(sp_description)), | |
| 86 | - parse_pdf(parse_pdf), | |
| 87 | - stream_id(stream_id), | |
| 88 | - obj_id(obj_id), | |
| 89 | - sanity_checks(sanity_checks) | |
| 80 | + input_(input), | |
| 81 | + object_description_(object_description), | |
| 82 | + tokenizer_(tokenizer), | |
| 83 | + decrypter_(decrypter), | |
| 84 | + context_(context), | |
| 85 | + description_(std::move(sp_description)), | |
| 86 | + parse_pdf_(parse_pdf), | |
| 87 | + stream_id_(stream_id), | |
| 88 | + obj_id_(obj_id), | |
| 89 | + sanity_checks_(sanity_checks) | |
| 90 | 90 | { |
| 91 | 91 | } |
| 92 | 92 | |
| ... | ... | @@ -133,32 +133,32 @@ class QPDFParser |
| 133 | 133 | // NB the offset includes any leading whitespace. |
| 134 | 134 | QPDFObjectHandle withDescription(Args&&... args); |
| 135 | 135 | void setDescription(std::shared_ptr<QPDFObject>& obj, qpdf_offset_t parsed_offset); |
| 136 | - InputSource& input; | |
| 137 | - std::string const& object_description; | |
| 138 | - qpdf::Tokenizer& tokenizer; | |
| 139 | - QPDFObjectHandle::StringDecrypter* decrypter; | |
| 140 | - QPDF* context; | |
| 141 | - std::shared_ptr<QPDFObject::Description> description; | |
| 142 | - bool parse_pdf{false}; | |
| 143 | - int stream_id{0}; | |
| 144 | - int obj_id{0}; | |
| 145 | - bool sanity_checks{false}; | |
| 146 | - | |
| 147 | - std::vector<StackFrame> stack; | |
| 148 | - StackFrame* frame{nullptr}; | |
| 136 | + InputSource& input_; | |
| 137 | + std::string const& object_description_; | |
| 138 | + qpdf::Tokenizer& tokenizer_; | |
| 139 | + QPDFObjectHandle::StringDecrypter* decrypter_; | |
| 140 | + QPDF* context_; | |
| 141 | + std::shared_ptr<QPDFObject::Description> description_; | |
| 142 | + bool parse_pdf_{false}; | |
| 143 | + int stream_id_{0}; | |
| 144 | + int obj_id_{0}; | |
| 145 | + bool sanity_checks_{false}; | |
| 146 | + | |
| 147 | + std::vector<StackFrame> stack_; | |
| 148 | + StackFrame* frame_{nullptr}; | |
| 149 | 149 | // Number of recent bad tokens. This will always be > 0 once a bad token has been encountered as |
| 150 | 150 | // it only gets incremented or reset when a bad token is encountered. |
| 151 | - int bad_count{0}; | |
| 151 | + int bad_count_{0}; | |
| 152 | 152 | // Number of bad tokens (remaining) before giving up. |
| 153 | - uint32_t max_bad_count{Limits::parser_max_errors()}; | |
| 153 | + uint32_t max_bad_count_{Limits::parser_max_errors()}; | |
| 154 | 154 | // Number of good tokens since last bad token. Irrelevant if bad_count == 0. |
| 155 | - int good_count{0}; | |
| 155 | + int good_count_{0}; | |
| 156 | 156 | // Start offset including any leading whitespace. |
| 157 | - qpdf_offset_t start{0}; | |
| 157 | + qpdf_offset_t start_{0}; | |
| 158 | 158 | // Number of successive integer tokens. |
| 159 | - int int_count{0}; | |
| 160 | - long long int_buffer[2]{0, 0}; | |
| 161 | - qpdf_offset_t last_offset_buffer[2]{0, 0}; | |
| 159 | + int int_count_{0}; | |
| 160 | + long long int_buffer_[2]{0, 0}; | |
| 161 | + qpdf_offset_t last_offset_buffer_[2]{0, 0}; | |
| 162 | 162 | bool empty_{false}; |
| 163 | 163 | }; |
| 164 | 164 | ... | ... |