A tax loophole that allows customers to buy pipe tobacco and make their own cigarettes may have cost New York State $17 million in lost taxes over the past two years.