-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redo fuzzer exercises to be based around tables
The previous bug using list items was not a good example. This also requires exploring a larger search space so we allow the browser to be reloaded using SIGHUP.
- Loading branch information
Showing
13 changed files
with
197 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
The bug is in the handling of a standard, common, HTML tag - specifically, an HTML tag which was *not* included in `browser.py`. | ||
The bug is in the handling of some standard, fairly common, HTML tags. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
Perhaps `browser.py` was feeling a bit listless. | ||
Although you're not allowed to look in `html_table.py`, perhaps the name of that file | ||
gives you some clues about what sorts of HTML tags might be involved? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
There are several standard HTML list tags - `ul`, `ol`, `li` (and various others). | ||
There are several standard HTML table tags - `tr`, `td`, `table` (and various others). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
There is a combination of these list-related tags which will cause the browser to crash. You should write code to generate random combinations of these tags and intervening data. | ||
There is a combination of these table-related tags which will cause the browser to crash. You should write code to generate random combinations of these tags and intervening data. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Solutions | ||
|
||
Example solutions (there may be others!) | ||
|
||
# Exercise 4b | ||
|
||
``` | ||
text = "" | ||
num = random.randrange(0, 12) | ||
for x in range(0, num): | ||
text += random.choice(["<tr>", "</tr>", "</td>", "<td>", "<table>", "</table>", "hello"]) | ||
return text | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
##################################### | ||
##################################### | ||
##################################### | ||
### DO NOT LOOK INSIDE THIS FILE! ### | ||
##################################### | ||
##################################### | ||
##################################### | ||
##################################### | ||
# This contains spoilers for exercise | ||
# 4b. Reading this code is cheating! | ||
##################################### | ||
##################################### | ||
##################################### | ||
##################################### | ||
|
||
class HTMLTable: | ||
def __init__(self): | ||
self.rows = list() | ||
|
||
def handle_tr_start(self): | ||
self.rows.append(list()) | ||
|
||
def handle_td_start(self): | ||
if len(self.rows) == 0: # no tr was found | ||
return | ||
self.rows[-1].append("") | ||
|
||
def handle_data(self, data): | ||
if len(self.rows) == 0: # no tr was found | ||
return | ||
if len(self.rows[-1]) == 0: # no td was found | ||
return | ||
self.rows[-1][-1] += data | ||
|
||
def handle_table_end(self, initial_y_pos, draw_at): | ||
""" | ||
Draws the table, using the passed function which takes | ||
x and y positions and content, draws the content, | ||
and returns a tuple of (x, y) space | ||
occupied. | ||
Returns the y position after the table is drawn. | ||
""" | ||
if len(self.rows) == 0: | ||
return initial_y_pos | ||
y_pos = initial_y_pos | ||
column_widths = list() | ||
first_row = True | ||
# Column widths are based on the first row space | ||
# occupied. A real algorithm would consider other rows. | ||
for row in self.rows: | ||
max_height = 0 | ||
if first_row: | ||
first_row = False | ||
for cell in row: | ||
current_x_pos = sum(column_widths) | ||
(width, height) = draw_at(current_x_pos, y_pos, cell) | ||
column_widths.append(width + 10) # padding | ||
max_height = max(max_height, height) | ||
else: | ||
current_x_pos = 0 | ||
for n, cell in enumerate(row): | ||
(_, height) = draw_at(current_x_pos, y_pos, cell) | ||
max_height = max(max_height, height) | ||
current_x_pos += column_widths[n] | ||
y_pos += max_height + 10 # padding | ||
return y_pos |
Oops, something went wrong.