protected function read()
    {
        $subSections = [];

        $startObject = $entryCount = $lastLineStart = null;
        $validityChecked = false;
        while (($line = $this->reader->readLine(20)) !== false) {
            if (\strpos($line, 'trailer') !== false) {
                $this->reader->reset($lastLineStart);
                break;
            }

            // jump over if line content doesn't match the expected string
            if (\sscanf($line, '%d %d', $startObject, $entryCount) !== 2) {
                continue;
            }

            $oldPosition = $this->reader->getPosition();
            $position = $oldPosition + $this->reader->getOffset();

            if (!$validityChecked && $entryCount > 0) {
                $nextLine = $this->reader->readBytes(21);
                /* Check the next line for maximum of 20 bytes and not longer
                 * By catching 21 bytes and trimming the length should be still 21.
                 */
                if (\strlen(\trim($nextLine)) !== 21) {
                    throw new CrossReferenceException(
                        'Cross-reference entries are larger than 20 bytes.',
                        CrossReferenceException::ENTRIES_TOO_LARGE
                    );
                }

                /* Check for less than 20 bytes: cut the line to 20 bytes and trim; have to result in exactly 18 bytes.
                 * If it would have less bytes the substring would get the first bytes of the next line which would
                 * evaluate to a 20 bytes long string after trimming.
                 */
                if (\strlen(\trim(\substr($nextLine, 0, 20))) !== 18) {
                    throw new CrossReferenceException(
                        'Cross-reference entries are less than 20 bytes.',
                        CrossReferenceException::ENTRIES_TOO_SHORT
                    );
                }

                $validityChecked = true;
            }

            $subSections[$position] = [$startObject, $entryCount];

            $lastLineStart = $position + $entryCount * 20;
            $this->reader->reset($lastLineStart);
        }

        // reset after the last correct parsed line
        $this->reader->reset($lastLineStart);

        if (\count($subSections) === 0) {
            throw new CrossReferenceException(
                'No entries found in cross-reference.',
                CrossReferenceException::NO_ENTRIES
            );
        }

        $this->subSections = $subSections;
    }