Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

farble across all channels, unpredictably #7793

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ using brave_shields::ControlType;

const char kEmbeddedTestServerDirectory[] = "canvas";
const char kTitleScript[] = "domAutomationController.send(document.title);";
const char kExpectedImageDataHashFarblingBalanced[] = "83";
const char kExpectedImageDataHashFarblingBalanced[] = "107";
const char kExpectedImageDataHashFarblingOff[] = "0";
const char kExpectedImageDataHashFarblingMaximum[] = "83";
const char kExpectedImageDataHashFarblingMaximum[] = "107";

class BraveOffscreenCanvasFarblingBrowserTest : public InProcessBrowserTest {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ BraveSessionCache::PerturbPixelsInternal(
// dimensions are less than SIZE_T_MAX. (Width and height are each
// limited to 32,767 pixels.)
const size_t pixel_count = data_buffer->Width() * data_buffer->Height();
// choose which channel (R, G, or B) to perturb
const uint8_t* first_byte = reinterpret_cast<const uint8_t*>(domain_key_);
uint8_t channel = *first_byte % 3;
// calculate initial seed to find first pixel to perturb, based on session
// key, domain key, and canvas contents
crypto::HMAC h(crypto::HMAC::SHA256);
Expand All @@ -209,11 +206,14 @@ BraveSessionCache::PerturbPixelsInternal(
canvas_key, sizeof canvas_key));
uint64_t v = *reinterpret_cast<uint64_t*>(canvas_key);
uint64_t pixel_index;
// choose which channel (R, G, or B) to perturb
uint8_t channel;
// iterate through 32-byte canvas key and use each bit to determine how to
// perturb the current pixel
for (int i = 0; i < 32; i++) {
uint8_t bit = canvas_key[i];
for (int j = 8; j >= 0; j--) {
channel = v % 3;
pixel_index = 4 * (v % pixel_count) + channel;
pixels[pixel_index] = pixels[pixel_index] ^ (bit & 0x1);
bit = bit >> 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const char kGetImageDataScript[] =
"domAutomationController.send(ctx.getImageData(0, 0, canvas.width, "
"canvas.height).data.reduce(adder));";

const int kExpectedImageDataHashFarblingBalanced = 83;
const int kExpectedImageDataHashFarblingBalanced = 107;
const int kExpectedImageDataHashFarblingOff = 0;
const int kExpectedImageDataHashFarblingMaximum =
kExpectedImageDataHashFarblingBalanced;
Expand Down