update_payload: Add zero operation support

Currenlty the applier.py and checker.py does not support ZERO
operation. This patch adds support for it. In addition, when generating
ZERO operation, we were not clearing the source length and extent
properties out of the protobuf. ZERO operation has no source length or
extent.

BUG=chromium:768461
TEST=unittest pass; scripts/paycheck.py --check payload.delta;

Change-Id: I766deaca4380686797893c2686036d59525546f4
Reviewed-on: https://chromium-review.googlesource.com/713539
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
Reviewed-by: Sen Jiang <senj@chromium.org>
diff --git a/scripts/update_payload/checker.py b/scripts/update_payload/checker.py
index 7404408..c613642 100644
--- a/scripts/update_payload/checker.py
+++ b/scripts/update_payload/checker.py
@@ -815,6 +815,24 @@
     if dst_extent:
       raise error.PayloadError('%s: excess dst blocks.' % op_name)
 
+  def _CheckZeroOperation(self, op, op_name):
+    """Specific checks for ZERO operations.
+
+    Args:
+      op: The operation object from the manifest.
+      op_name: Operation name for error reporting.
+
+    Raises:
+      error.PayloadError if any check fails.
+    """
+    # Check: Does not contain src extents, data_length and data_offset.
+    if op.src_extents:
+      raise error.PayloadError('%s: contains src_extents.' % op_name)
+    if op.data_length:
+      raise error.PayloadError('%s: contains data_length.' % op_name)
+    if op.data_offset:
+      raise error.PayloadError('%s: contains data_offset.' % op_name)
+
   def _CheckAnyDiffOperation(self, data_length, total_dst_blocks, op_name):
     """Specific checks for BSDIFF, SOURCE_BSDIFF and PUFFDIFF operations.
 
@@ -972,6 +990,8 @@
     elif op.type == common.OpType.MOVE and self.minor_version == 1:
       self._CheckMoveOperation(op, data_offset, total_src_blocks,
                                total_dst_blocks, op_name)
+    elif op.type == common.OpType.ZERO and self.minor_version >= 4:
+      self._CheckZeroOperation(op, op_name)
     elif op.type == common.OpType.BSDIFF and self.minor_version == 1:
       self._CheckAnyDiffOperation(data_length, total_dst_blocks, op_name)
     elif op.type == common.OpType.SOURCE_COPY and self.minor_version >= 2:
@@ -1039,6 +1059,7 @@
         common.OpType.REPLACE: 0,
         common.OpType.REPLACE_BZ: 0,
         common.OpType.MOVE: 0,
+        common.OpType.ZERO: 0,
         common.OpType.BSDIFF: 0,
         common.OpType.SOURCE_COPY: 0,
         common.OpType.SOURCE_BSDIFF: 0,