Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_new_clear_hidden_not_initialized():
iso = pycdlib.PyCdlib()
iso.new()
aastr = b"aa\n"
iso.add_fp(BytesIO(aastr), len(aastr), "/AAAAAAAA.;1")
iso.close()
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput):
iso.clear_hidden("/AAAAAAAA.;1")
def test_split_path_no_leading_slash():
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInvalidInput) as exc_info:
pycdlib.utils.split_path(b'foo/bar')
assert(str(exc_info.value) == 'Must be a path starting with /')
def test_rrsprecord_parse_double_initialized():
sp = pycdlib.rockridge.RRSPRecord()
sp.parse(b'SP\x07\x01\xbe\xef\x00')
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
sp.parse(b'SP\x07\x01\xbe\xef\x00')
assert(str(excinfo.value) == 'SP record already initialized')
def parse(self, data, extent):
# type: (bytes, int) -> None
'''
Parse the passed in data into a UDF BEA Volume Structure.
Parameters:
data - The data to parse.
extent - The extent that this descriptor currently lives at.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('BEA Volume Structure already initialized')
(structure_type, standard_ident, structure_version,
reserved_unused) = struct.unpack_from(self.FMT, data, 0)
if structure_type != 0:
raise pycdlibexception.PyCdlibInvalidISO('Invalid structure type')
if standard_ident != b'BEA01':
raise pycdlibexception.PyCdlibInvalidISO('Invalid standard identifier')
if structure_version != 1:
raise pycdlibexception.PyCdlibInvalidISO('Invalid structure version')
self.orig_extent_loc = extent
self._initialized = True
def read(self, size=None):
# type: (Optional[int]) -> bytes
'''
Read and return up to size bytes.
Parameters:
size - Optional parameter to read size number of bytes; if None or
negative, all remaining bytes in the file will be read
Returns:
The number of bytes requested or the rest of the data left in the file,
whichever is smaller. If the file is at or past EOF, returns an empty
bytestring.
'''
if not self._open:
raise pycdlibexception.PyCdlibInvalidInput('I/O operation on closed file.')
if self._offset >= self._length:
return b''
if size is None or size < 0:
data = self.readall()
else:
readsize = min(self._length - self._offset, size)
data = self._fp.read(readsize)
self._offset += readsize
return data
def add_boot_info_table(self, boot_info_table):
# type: (eltorito.EltoritoBootInfoTable) -> None
'''
Add a boot info table to this Inode.
Parameters:
boot_info_table - The Boot Info Table object to add to this Inode.
Returns:
Nothing.
'''
if not self._initialized:
raise pycdlibexception.PyCdlibInternalError('Inode is not initialized')
self.boot_info_table = boot_info_table
def new(self, text):
# type: (bytes) -> None
'''
Create a new file or text identifier.
Parameters:
text - The text to store into the identifier.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('This File or Text identifier is already initialized')
if len(text) != 128:
raise pycdlibexception.PyCdlibInvalidInput('Length of text must be 128')
self.text = text
self._initialized = True
else:
if self.parent.rock_ridge is None:
raise pycdlibexception.PyCdlibInvalidISO('Parent of the entry did not have Rock Ridge, ISO is corrupt')
if self.file_ident == b'\x00':
# If we are adding the dot directory, increment the parent
# file links and our file links.
self.parent.rock_ridge.add_to_file_links()
self.rock_ridge.add_to_file_links()
elif self.file_ident == b'\x01':
# If we are adding the dotdot directory, copy the file links
# from the dot directory of the grandparent.
if self.parent.parent is None:
raise pycdlibexception.PyCdlibInternalError('Grandparent of the entry did not exist; this cannot be')
if not self.parent.children:
raise pycdlibexception.PyCdlibInvalidISO('Grandparent of the entry did not have a dot entry; ISO is corrupt')
if self.parent.parent.children[0].rock_ridge is None:
raise pycdlibexception.PyCdlibInvalidISO('Grandparent dotdot entry did not have Rock Ridge; ISO is corrupt')
self.rock_ridge.copy_file_links(self.parent.parent.children[0].rock_ridge)
else:
# For all other entries, increment the parents file links
# and the parents dot file links.
self.parent.rock_ridge.add_to_file_links()
if not self.parent.children:
raise pycdlibexception.PyCdlibInvalidISO('Parent of the entry did not have a dot entry; ISO is corrupt')
if self.parent.children[0].rock_ridge is None:
raise pycdlibexception.PyCdlibInvalidISO('Dot child of the parent did not have a dot entry; ISO is corrupt')
self.parent.children[0].rock_ridge.add_to_file_links()
def new(self):
# type: () -> None
'''
Create a new Directory Record date based on the current time.
Parameters:
tm - An optional argument that must be None
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('Directory Record Date already initialized')
# This algorithm was ported from cdrkit, genisoimage.c:iso9660_date()
tm = time.time()
local = time.localtime(tm)
self.years_since_1900 = local.tm_year - 1900
self.month = local.tm_mon
self.day_of_month = local.tm_mday
self.hour = local.tm_hour
self.minute = local.tm_min
self.second = local.tm_sec
self.gmtoffset = utils.gmtoffset_from_tm(tm, local)
self._initialized = True
'''
Parse an Extended Attribute Record out of a string.
Parameters:
xastr - The string to parse.
Returns:
Nothing.
'''
if self._initialized:
raise pycdlibexception.PyCdlibInternalError('This XARecord is already initialized')
(self._group_id, self._user_id, self._attributes, signature, self._filenum,
unused) = struct.unpack_from(self.FMT, xastr, 0)
if signature != b'XA':
raise pycdlibexception.PyCdlibInvalidISO('Invalid signature on the XARecord!')
if unused != b'\x00\x00\x00\x00\x00':
raise pycdlibexception.PyCdlibInvalidISO('Unused fields should be 0')
self._initialized = True