DUBAI, OCT. 7 -- Iranian gunboats attacked a Saudi tanker in the Persian Gulf today and Tehran warned that the western naval buildup in the waterway might lead to "catastrophe."

Shipping sources said the Iranians fired rocket-propelled grenades and armor-piercing rockets at the 21,032-ton Raad al Bakry off the Dubai coast. Damage was said to be minor, and no casualties were reported. The attack came two days after Iraqi jets struck five Iranian-operated supertankers used to store petroleum near the mouth of the gulf.

One tanker, Shining Star, which was set ablaze in that raid Monday, was still smoldering, shipping sources said.

In an attempt to help gulf forces protect shipping, Japan announced yesterday that it would provide an advanced ship-tracking system.

Chief Cabinet Secretary Masaharu Gotoda, who announced the move, also promised increased contributions to the stationing of U.S. forces in Japan, apparently to offset the cost of U.S. Navy missions in the gulf.

Meanwhile, Iranian Parliamentary Speaker Ali Akbar Hashemi Rafsanjani warned that the western military buildup in the gulf might lead to a "catastrophe," Iran's state news agency said.

In a meeting with the Belgian ambassador in Tehran, Victor Allard, the Iranian leader also criticized Western European nations for following the United States in sending their fleets to the gulf, the agency said.

Iranian sources quoted by the agency said, meanwhile, that Iran and the Soviet Union had agreed to resume airline flights later this month between Tehran and Moscow. The Soviet carrier Aeroflot suspended flights after Iraq declared Iran's airspace a war zone in March 1985.

Tehran and Moscow also agreed to set up a shipping line to serve Iranian and Soviet ports in the Caspian Sea, which lies between the two countries.