According to page C17 of this NIST document:

http://ts.nist.gov/WeightsAndMeasures/Publications/upload/h4402_appenc.pdf

"by custom, 42 gallons comprise a barrel of crude oil or petroleum products for statistical purposes, and this equivalent is recognized "for liquids" by four States."

Based on the above, it should be noted that (a) the definition of 42 gallons is "by custom" - not "by law", and (b) the definition of 42 gallons is "for statistical purposes" and does not mention "for use in trade or commerce".

This NIST document (page 10) also states that a barrel of oil is 42 gallons (approx. 159 liters):

http://ts.nist.gov/WeightsAndMeasures/Metric/upload/fs376-b.pdf 

NYMEX does define the capacity of a barrel in terms of gallons according to this:

http://www.nymex.com/CL_spec.aspx

Here we see that the trading unit (for Light Sweet Crude Oil) is specified as "1,000 barrels (42,000 gallons)".