--- a/Lib/importlib/abc.py Wed Jun 27 15:26:26 2012 -0400 +++ b/Lib/importlib/abc.py Thu Jun 28 08:37:44 2012 -0700 @@ -282,7 +282,11 @@ if len(raw_timestamp) < 4: raise EOFError("bad timestamp in {}".format(fullname)) pyc_timestamp = _bootstrap._r_long(raw_timestamp) - bytecode = data[8:] + raw_file_size = data[8:12] + if len(raw_file_size) < 4: + raise EOFError("bad file size in {}".format(fullname)) + file_size = _bootstrap._r_long(raw_file_size) + bytecode = data[12:] # Verify that the magic number is valid. if imp.get_magic() != magic: raise ImportError( @@ -316,9 +320,11 @@ code_object = compile(source, source_path, 'exec', dont_inherit=True) # Generate bytecode and write it out. if not sys.dont_write_bytecode: + bytecode = marshal.dumps(code_object) data = bytearray(imp.get_magic()) data.extend(_bootstrap._w_long(source_timestamp)) - data.extend(marshal.dumps(code_object)) + data.extend(_bootstrap._w_long(len(source))) + data.extend(bytecode) self.write_bytecode(fullname, data) return code_object