Index: pathfind.c
===================================================================
--- pathfind.c	(revision 640)
+++ pathfind.c	(working copy)
@@ -258,11 +258,16 @@
 	RememberData rd;
 	uint tile_org = tile;
 
-	if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) &&
-			(_map5[tile] & 0xF0)==0 && 
-			(_map5[tile] & 3) == direction &&
-			((_map5[tile]>>1)&6) == tpf->tracktype) {
-		tile = SkipToEndOfTunnel(tpf, tile, direction);		
+	if (IS_TILETYPE(tile, MP_TUNNELBRIDGE)) {
+		if ((_map5[tile] & 0xF0)==0 &&
+		    (_map5[tile] & 3) == direction &&
+		    ((_map5[tile]>>1)&6) == tpf->tracktype) {
+			tile = SkipToEndOfTunnel(tpf, tile, direction);		
+		} else {
+			// This does not belong to us anymore, ie. a track
+			// laid on top of a tunnel near tunnel endpoint.
+			return;
+		}
 	} else {
 		tile += _tileoffs_by_dir[direction];
 		tpf->rd.cur_length++;
@@ -592,13 +597,18 @@
 	si.state = 0;
 
 restart:
-	if (IS_TILETYPE(tile, MP_TUNNELBRIDGE) &&
-			(_map5[tile] & 0xF0)==0 && 
-			(uint)(_map5[tile] & 3) == direction &&
-			((_map5[tile]>>1)&6) == tpf->tracktype) {
-		flotr = FindLengthOfTunnel(tile, direction, tpf->tracktype);
-		si.cur_length += flotr.length;
-		tile = flotr.tile;
+	if (IS_TILETYPE(tile, MP_TUNNELBRIDGE)) {
+		if ((_map5[tile] & 0xF0)==0 &&
+		    (_map5[tile] & 3) == direction &&
+		    ((_map5[tile]>>1)&6) == tpf->tracktype) {
+			flotr = FindLengthOfTunnel(tile, direction, tpf->tracktype);
+			si.cur_length += flotr.length;
+			tile = flotr.tile;
+		} else {
+			// This does not belong to us anymore, ie. a track
+			// laid on top of a tunnel near tunnel endpoint.
+			goto popnext;
+		}
 	}
 	// remember the start tile so we know if we're in an inf loop.
 	tile_org = tile;
