{"action":"opened","issue":{"url":"https://api.github.com/repos/yob/pdf-reader/issues/314","repository_url":"https://api.github.com/repos/yob/pdf-reader","labels_url":"https://api.github.com/repos/yob/pdf-reader/issues/314/labels{/name}","comments_url":"https://api.github.com/repos/yob/pdf-reader/issues/314/comments","events_url":"https://api.github.com/repos/yob/pdf-reader/issues/314/events","html_url":"https://github.com/yob/pdf-reader/issues/314","id":526753430,"node_id":"MDU6SXNzdWU1MjY3NTM0MzA=","number":314,"title":"creating page layout uses a lot of memory","user":{"login":"Jasmeet107","id":5570793,"node_id":"MDQ6VXNlcjU1NzA3OTM=","avatar_url":"https://avatars2.githubusercontent.com/u/5570793?v=4","gravatar_id":"","url":"https://api.github.com/users/Jasmeet107","html_url":"https://github.com/Jasmeet107","followers_url":"https://api.github.com/users/Jasmeet107/followers","following_url":"https://api.github.com/users/Jasmeet107/following{/other_user}","gists_url":"https://api.github.com/users/Jasmeet107/gists{/gist_id}","starred_url":"https://api.github.com/users/Jasmeet107/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jasmeet107/subscriptions","organizations_url":"https://api.github.com/users/Jasmeet107/orgs","repos_url":"https://api.github.com/users/Jasmeet107/repos","events_url":"https://api.github.com/users/Jasmeet107/events{/privacy}","received_events_url":"https://api.github.com/users/Jasmeet107/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-11-21T17:59:51Z","updated_at":"2019-11-21T17:59:51Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"When a pdf has a lot of really small characters in it, reading the PDF can use a huge amount of memory. \r\n\r\nin `page_layout.rb`:\r\n``` def to_s\r\n      return \"\" if @runs.empty?\r\n\r\n      page = row_count.times.map { |i| \" \" * col_count }\r\n      @runs.each do |run|\r\n        x_pos = ((run.x - @x_offset) / col_multiplier).round\r\n        y_pos = row_count - (run.y / row_multiplier).round\r\n        if y_pos <= row_count && y_pos >= 0 && x_pos <= col_count && x_pos >= 0\r\n          local_string_insert(page[y_pos-1], run.text, x_pos)\r\n        end\r\n      end\r\n      interesting_rows(page).map(&:rstrip).join(\"\\n\")\r\n    end```\r\n\r\nspecifically the second line of this method creates a really large array in some cases\r\n\r\nthe dimensions of this array are calculated using `internal_show_text` in `page_text_receiver.rb`, which is using the average font size of all characters. when there are a lot of characters with tiny font sizes (as pdfs often have, like small symbols etc.), it means the widths and heights of the rows and columns to create this array will be super small, thus resulting in cases of 100k x 100k (or even more) arrays. this is such a big array that it's crashing our application in these cases. \r\n\r\n@EugeneNF has also been working on this"}}
{"actor":{"display_login":"Jasmeet107"}}