They dont attacked Ukrainians but with help of UKRAINIAN troops they fought with Russians and it is big difference. In that time Ukraine cannot be an independent country, as always before, question was who take that land Russia or Poland. Russians where there, it was too dangerous for Poland.When polish troops would give Ukrainians independent country, immediately they would have Russians there and Poland cannot had Russians so close their borders. In Poland Ukrainians were in fact free people, they had the same rights like Poles, in Russia even Russians dont have too many things to say Now at last they are independent country and good for them!
Also, it is important to acknowledge that the Poles fought several wars in the '20s and '30s, including in Upper Silesia, which had a significant German population to whom Poland was not charitable.
Poland's activities of the previous decades had thus made it an attractive target for both Russia and Germany. Not that the invasion was at all justified -- it just made Poland an obvious first choice for the expansionist aims of both invaders.