A door to an apartment where a fire was started by a malfunctioning electric space heater and the door to a stairwell were left open, allowing smoke to billow through all floors of a 19-story building in New York City, trapping people who sought to escape and killing 17, including eight children, fire officials said.