1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00
serenity/Userland/Libraries
Nico Weber 87112dcbdc LibPDF: Return null for invalid refs, tolerate null objects as outline
https://llvm.org/devmtg/2022-11/slides/TechTalk5-WhatDoesItTakeToRunLLVMBuildbots.pdf
has an xref table that starts like so:

```
xref
0 214
0000000002 65535 f
0000924663 00000 n
0000000003 00000 f
0000000000 00000 f
0000000016 00000 n
0000000160 00000 n
0000000263 00000 n
```

This is a list of objects in the PDF file. The lines ending with 'f'
mean that this object is "free", that is it's not stored in the file.
In this file, objects 0, 2, 3 are free. For free objects, the first
number is the offset of the next free object: Object 0 refers to object
2, 2 to 3, and 3 back to 0 (since it's the last free object).
The lines ending with "n" are actual objects; here the first number is
a byte offset to where that object is stored in the file.

Furthermore, the file contains

```
/Outlines
2
0
R
```

in its root object, meaning that object 2 stores the page outlines.

Since object 2 is set as free, there is no object 2. But the spec
says that an invalid object reference is just the null object.

This patch makes us return null objects for references to free
objects, and it also makes us treat a null object as /Outlines value
the same as not having /Outlines in the first place.

Fixes #23023 -- we can now open that file. (We don't render it super
well, but only for already-known reasons.)

Since I found it a bit confusing: XRefTable has two related methods
here:

1. has_object() returns if an object was explicitly listed in an
   xref table. The first number right after `xref` is the start
   index. So if an xref table were to start with `10`, we'd implicitly
   create 10 trailing objects for which has_object() would return false
2. is_object_in_use() returns true if an object that was in a table
   (i.e. one where has_object() returns true) was listed with 'n' and
   false if it was listed with 'f'.

DocumentParser::parse_object_with_index() should probably return a null
object for the `!has_object()` case as well instead of VERIFY()ing
that has_object() is true. But I haven't seen this in the wild yet,
so keeping as-is for now.
2024-01-31 12:10:19 -05:00
..
LibAccelGfx LibAccelGfx+LibWeb+WebContent: Handle OpenGL Context init errors 2024-01-24 19:43:51 +01:00
LibArchive Everywhere: Use to_number<T> instead of to_{int,uint,float,double} 2023-12-23 20:41:07 +01:00
LibAudio LibAudio: Avoid UAF when loading WAV metadata 2024-01-17 16:09:59 -05:00
LibC LibC+LibELF: Pass information from linker via magic lookup 2024-01-24 22:17:49 -07:00
LibCards Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibChess Everywhere: Use to_number<T> instead of to_{int,uint,float,double} 2023-12-23 20:41:07 +01:00
LibCMake LibSyntax+Userland: Make LibSyntax not depend on LibGUI 2023-08-29 07:57:39 -04:00
LibCodeComprehension Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibCompress LibCompress/Deflate: Remove three useless FIXMEs 2024-01-14 21:22:35 +01:00
LibConfig Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibCore LibCore: Refactor template definitions to header in ArgsParser 2024-01-29 13:58:37 +00:00
LibCoredump Everywhere: Remove references to UserspaceEmulator 2024-01-29 20:20:55 +00:00
LibCpp Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibCrypt Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibCrypto LibCrypto: Add support for the POSIX cksum algorithm 2024-01-18 18:01:26 +03:30
LibDebug Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibDesktop LibDesktop: Add menu_name() to AppFile 2024-01-14 15:16:45 -07:00
LibDeviceTree Userland: Remove LibCore dependency from libraries that do not use it 2024-01-22 08:48:34 -05:00
LibDiff AK: Remove ByteString from GenericLexer 2024-01-12 17:03:53 -07:00
LibDNS Userland: Remove LibCore dependency from libraries that do not use it 2024-01-22 08:48:34 -05:00
LibDSP Userland: Remove LibCore dependency from libraries that do not use it 2024-01-22 08:48:34 -05:00
LibEDID Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibELF LibC+LibELF: Pass information from linker via magic lookup 2024-01-24 22:17:49 -07:00
LibFileSystem LibFileSystem+Everywhere: Return ByteString from read_link() 2024-01-16 08:42:34 +00:00
LibFileSystemAccessClient LibFileSystemAccessClient+Userland: Return file paths as ByteStrings 2024-01-29 23:14:39 +00:00
LibGemini Everywhere: Use to_number<T> instead of to_{int,uint,float,double} 2023-12-23 20:41:07 +01:00
LibGfx LibGfx+Tests: Improve calculation of restart interval 2024-01-30 14:50:43 +01:00
LibGL Userland: Remove LibCore dependency from libraries that do not use it 2024-01-22 08:48:34 -05:00
LibGLSL LibGLSL: Add tests for GLSL parser 2023-08-18 15:29:48 +02:00
LibGPU Userland: Remove LibCore dependency from libraries that do not use it 2024-01-22 08:48:34 -05:00
LibGUI LibGUI+WindowServer: Add menu minimum width support 2024-01-29 05:29:41 -07:00
LibHTTP LibHTTP: Ensure the ending \r\n is present before trying to read a line 2024-01-21 21:13:58 +01:00
LibIDL LibFileSystem+Userland: Return ByteString from real_path() 2024-01-16 08:42:34 +00:00
LibImageDecoderClient ImageDecoder: Add plumbing to allow a client to request an ideal size 2024-01-07 20:10:22 +01:00
LibIMAP Everywhere: Use to_number<T> instead of to_{int,uint,float,double} 2023-12-23 20:41:07 +01:00
LibIPC LibIPC: Avoid redundant copy of every tranferred IPC message 2024-01-03 10:17:00 +01:00
LibJIT Userland: Remove LibCore dependency from libraries that do not use it 2024-01-22 08:48:34 -05:00
LibJS LibJS/Bytecode: Apply BigInt/Symbol ToObject avoidance in another place 2024-01-28 19:49:51 -05:00
LibKeyboard Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibLine AK: Remove ByteString from GenericLexer 2024-01-12 17:03:53 -07:00
LibLocale Userland: Remove LibCore dependency from libraries that do not use it 2024-01-22 08:48:34 -05:00
LibMain
LibManual Everywhere: Use to_number<T> instead of to_{int,uint,float,double} 2023-12-23 20:41:07 +01:00
LibMarkdown Everywhere: Use to_number<T> instead of to_{int,uint,float,double} 2023-12-23 20:41:07 +01:00
LibPartition Everywhere: Remove needless trailing semi-colons after functions 2023-07-08 10:32:56 +01:00
LibPCIDB Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibPDF LibPDF: Return null for invalid refs, tolerate null objects as outline 2024-01-31 12:10:19 -05:00
LibProtocol LibProtocol: Don't assume request creation will succeed across IPC 2024-01-10 23:37:57 +01:00
LibRegex Userland: Remove LibCore dependency from libraries that do not use it 2024-01-22 08:48:34 -05:00
LibRIFF Userland: Remove LibCore dependency from libraries that do not use it 2024-01-22 08:48:34 -05:00
LibSanitizer LibSanitizer: Add _abort variants of UBSan handlers 2023-08-13 05:14:07 +02:00
LibSoftGPU LibSoftGPU: Optimize GPU::Vertex lists 2023-10-15 12:14:07 +02:00
LibSQL LibSQL: Allow constructing SQL values from a String 2024-01-26 20:22:39 +01:00
LibSymbolication AK+Everywhere: Remove JsonValue APIs with implicit default values 2024-01-21 15:47:53 -07:00
LibSyntax Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibSystem Everywhere: Resolve conflicts with LibC and libc++ 2023-06-27 12:40:38 +02:00
LibTest LibFileSystem+Userland: Return ByteString from real_path() 2024-01-16 08:42:34 +00:00
LibTextCodec LibTextCodec+AK: Don't validate UTF-8 strings twice 2023-12-30 13:49:50 +01:00
LibThreading Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibTimeZone Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibTLS LibTLS: Notify the client for app data as soon as some data is available 2024-01-03 14:59:59 +01:00
LibUnicode Userland: Remove LibCore dependency from libraries that do not use it 2024-01-22 08:48:34 -05:00
LibUSBDB Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibVideo LibVideo: Replace DeprecatedFlyString with FlyString 2024-01-14 15:00:13 -07:00
LibVirtGPU LibGL+Lib*GPU: Set model view and projection matrices separately 2023-10-15 12:14:07 +02:00
LibVT LibVT: Emit different sequences while in keypad application mode 2024-01-16 17:55:17 +03:30
LibWasm Everywhere: Use to_number<T> instead of to_{int,uint,float,double} 2023-12-23 20:41:07 +01:00
LibWeb LibWeb: Remove contained_by_inline_node flag in PaintableFragment 2024-01-31 07:15:49 +01:00
LibWebSocket Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibWebView LibWebView: Port the CookieJar to String 2024-01-26 20:22:39 +01:00
LibX86 Everywhere: Rename {Deprecated => Byte}String 2023-12-17 18:25:10 +03:30
LibXML AK: Remove ByteString from GenericLexer 2024-01-12 17:03:53 -07:00
CMakeLists.txt LibAudio+LibRIFF: Move general RIFF handling to LibRIFF 2024-01-15 23:23:26 -07:00