MCPcopy Create free account
hub / github.com/cgsecurity/testdisk / read_pdf_file

Function read_pdf_file

src/file_pdf.c:439–463  ·  view source on GitHub ↗

@ @ requires \valid_read(buffer+(0..512-1)); @ assigns \nothing; @*/

Source from the content-addressed store, hash-verified

437 @ assigns \nothing;
438 @*/
439static uint64_t read_pdf_file(const unsigned char *buffer)
440{
441 const unsigned char sig_linearized[10]={'L','i','n','e','a','r','i','z','e','d'};
442 const char *src;
443 unsigned int i;
444 const char *sbuffer=(const char *)buffer;
445 src=(const char *)td_memmem(sbuffer, 512, sig_linearized, sizeof(sig_linearized));
446 if(src == NULL)
447 return 0;
448 i = src - sbuffer;
449 i+=sizeof(sig_linearized);
450 if( i >= 512 -1)
451 return 0;
452 /*@ assert i < 512-1; */
453 /*@
454 @ loop assigns i;
455 @ loop variant 512 - 1 - i;
456 @ */
457 for(; i < 512-1 && buffer[i]!='>'; i++)
458 {
459 if(buffer[i]=='/' && buffer[i+1]=='L')
460 return read_pdf_file_aux(buffer, i+2);
461 }
462 return 0;
463}
464
465/*@
466 @ requires buffer_size >= 512;

Callers 1

header_check_pdfFunction · 0.85

Calls 2

td_memmemFunction · 0.85
read_pdf_file_auxFunction · 0.85

Tested by

no test coverage detected