diff --git a/accessible/src/html/nsHTMLTableAccessible.cpp b/accessible/src/html/nsHTMLTableAccessible.cpp
index 2ead768140e6..bfcd7fdf35fa 100644
--- a/accessible/src/html/nsHTMLTableAccessible.cpp
+++ b/accessible/src/html/nsHTMLTableAccessible.cpp
@@ -895,8 +895,16 @@ nsHTMLTableAccessible::GetCellAt(PRInt32 aRow, PRInt32 aColumn,
nsCOMPtr cellContent(do_QueryInterface(cellElement));
nsAccessible *cell =
GetAccService()->GetAccessibleInWeakShell(cellContent, mWeakShell);
- if (cell)
- CallQueryInterface(cell, aTableCellAccessible);
+
+ if (!cell) {
+ return NS_ERROR_INVALID_ARG;
+ }
+
+ if (cell != this) {
+ // XXX bug 576838: crazy tables (like table6 in tables/test_table2.html) may
+ // return itself as a cell what makes Orca hang.
+ NS_ADDREF(*aTableCellAccessible = cell);
+ }
return NS_OK;
}
diff --git a/accessible/tests/mochitest/table/test_table_2.html b/accessible/tests/mochitest/table/test_table_2.html
index bd52a1688822..4b82b33abe6f 100644
--- a/accessible/tests/mochitest/table/test_table_2.html
+++ b/accessible/tests/mochitest/table/test_table_2.html
@@ -76,6 +76,11 @@ function doTest()
accNotCreated = (!isAccessible("t5_cell"));
ok(accNotCreated, "wrongly created table cell accessible");
+ // test crazy table
+ var table6 = getAccessible("table6", [nsIAccessibleTable]);
+ ok(!table6.getCellAt(0, 0),
+ "We don't expect cell accessible for crazy table 6!");
+
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
@@ -138,6 +143,11 @@ addA11yLoadEvent(doTest);
+
+