mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 05:32:44 +00:00 
			
		
		
		
	LibWeb: Add convenience methods {,de}serialize_{u,i}64()
To avoid differing logic for serializing and deserializing similar types, move the logic into separate helpers. Also, adds security checks like VERIFY to avoid reading past the end of the serialized data. If we try to read past the end of the serialized data, either our program logic is wrong or our serialized data has somehow been corrupted. Therefore, at least currently, it is better to crash by VERIFYing.
This commit is contained in:
		
							parent
							
								
									d269ac611e
								
							
						
					
					
						commit
						4751ab9f0b
					
				
					 3 changed files with 38 additions and 11 deletions
				
			
		|  | @ -106,7 +106,7 @@ WebIDL::ExceptionOr<void> File::serialization_steps(HTML::SerializationRecord& r | |||
|     TRY(HTML::serialize_string(vm, record, m_name)); | ||||
| 
 | ||||
|     // 4. Set serialized.[[LastModified]] to the value of value’s lastModified attribute.
 | ||||
|     record.append(bit_cast<u32*>(&m_last_modified), 2); | ||||
|     HTML::serialize_i64(record, m_last_modified); | ||||
| 
 | ||||
|     return {}; | ||||
| } | ||||
|  | @ -128,10 +128,7 @@ WebIDL::ExceptionOr<void> File::deserialization_steps(ReadonlySpan<u32> const& r | |||
|     m_name = TRY(HTML::deserialize_string(vm, record, position)); | ||||
| 
 | ||||
|     // 4. Initialize the value of value’s lastModified attribute to serialized.[[LastModified]].
 | ||||
|     u32 bits[2] = {}; | ||||
|     bits[0] = record[position++]; | ||||
|     bits[1] = record[position++]; | ||||
|     m_last_modified = *bit_cast<i64*>(&bits); | ||||
|     m_last_modified = HTML::deserialize_i64(record, position); | ||||
| 
 | ||||
|     return {}; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Kenneth Myhra
						Kenneth Myhra