Commit 67308a39 authored by Jim Nelson's avatar Jim Nelson

Further tweaks I found after the changes I made this morning.

parent ec302fba
...@@ -500,7 +500,7 @@ private class AVIMetadataLoader { ...@@ -500,7 +500,7 @@ private class AVIMetadataLoader {
ulong timestamp = 0; ulong timestamp = 0;
try { try {
chunk.open_file(); chunk.open_file();
chunk.skip(12); // Advance past 12 byte header. chunk.nonsection_skip(12); // Advance past 12 byte header.
string sdate = read_section(chunk); string sdate = read_section(chunk);
if (null != sdate) { if (null != sdate) {
timestamp = parse_date(sdate.strip()); timestamp = parse_date(sdate.strip());
...@@ -552,6 +552,10 @@ private class AVIChunk { ...@@ -552,6 +552,10 @@ private class AVIChunk {
} }
} }
public void nonsection_skip(uint64 skip_amount) throws GLib.Error {
skip_uint64(input, skip_amount);
}
public void skip(uint64 skip_amount) throws GLib.Error { public void skip(uint64 skip_amount) throws GLib.Error {
advance_section_offset(skip_amount); advance_section_offset(skip_amount);
skip_uint64(input, skip_amount); skip_uint64(input, skip_amount);
...@@ -561,11 +565,9 @@ private class AVIChunk { ...@@ -561,11 +565,9 @@ private class AVIChunk {
return new AVIChunk.with_input_stream(input, this); return new AVIChunk.with_input_stream(input, this);
} }
private void advance_section_offset(uint64 amount) throws Error { private void advance_section_offset(uint64 amount) {
if ((section_offset + amount) > section_size) { if ((section_offset + amount) > section_size)
throw new IOError.FAILED("Attempted to advance %d bytes past end of section", amount = section_size - section_offset;
(section_offset + amount) - section_size);
}
section_offset += amount; section_offset += amount;
if (null != parent) { if (null != parent) {
...@@ -578,19 +580,21 @@ private class AVIChunk { ...@@ -578,19 +580,21 @@ private class AVIChunk {
return input.read_byte(); return input.read_byte();
} }
public uint32 read_uint32() throws GLib.Error {
advance_section_offset(4);
return input.read_uint32();
}
public uint16 read_uint16() throws GLib.Error { public uint16 read_uint16() throws GLib.Error {
advance_section_offset(2); advance_section_offset(2);
return input.read_uint16(); return input.read_uint16();
} }
public void read_chunk() throws GLib.Error { public void read_chunk() throws GLib.Error {
section_name = read_name(); // don't use checked reads here because they advance the section offset, which we're trying
section_size = read_uint32(); // to determine here
GLib.StringBuilder sb = new GLib.StringBuilder();
sb.append_c((char) input.read_byte());
sb.append_c((char) input.read_byte());
sb.append_c((char) input.read_byte());
sb.append_c((char) input.read_byte());
section_name = sb.str;
section_size = input.read_uint32();
section_offset = 0; section_offset = 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment