Dvc: stage: ruamel.yaml loads md5 as inf

Created on 20 May 2019  路  8Comments  路  Source: iterative/dvc

* information about your setup*
DVC version(0.40.3 or 0.40.4), Platform and method of installation (pip), DEB(Linux Mint),

I've just upgraded from 0.35 and suddenly got that error:
image

bug p0-critical

All 8 comments

diff --git a/dvc/utils/stage.py b/dvc/utils/stage.py
index e88f3c2..178c5c8 100644
--- a/dvc/utils/stage.py
+++ b/dvc/utils/stage.py
@@ -13,8 +13,8 @@ def load_stage_file(path):

 def load_stage_fd(fd, path):
     try:
-        yaml = YAML()
-        return yaml.load(fd) or {}
+        import yaml
+        return yaml.safe_load(fd)
     except YAMLError as exc:
         raise StageFileCorruptedError(path, cause=exc)

looks like a ruamel issue. Replacing it with pyyaml fixes it.

Looks like for some reason this specific value md5: 4661e177303623051910790245640135 is triggering the bug:

md5: 4661e177303623051910790245640135  
outs:                                  
- cache: true                          
  md5: 90104d9e83cfb825cf45507e90aadd27
  metric: false                        
  path: dvc.ico                        

This looks like float value <mantissa>e<exponent>.

@efiop , I'm not sure if we already have a test to check for backward compatibility with stage file checksums, but I think it is important to not affect this.

This turned out to be a tricky inconsistency between PyYAML and ruamel.yaml. They have different notions of what looks-like-number means:

ruamel.yaml thinks '4661e177303623051910790245640135' looks like number and quotes it on dump, loads as string. PyYAML thinks that no, this is not a number, and dumps it unquoted and subsequently loads it as string, because again "this is not a number".

The issue arises when you try to load unquoted thing like above with ruamel.yaml it loads it as number, which is too big and becomes inf. We switched from PyYAML to ruamel.yaml, which made this scenario possible.

This looks like very rare occasion, so for anyone running into this the solution would be to just quote a tricky checksum manually. Everything should work smoothly after that and never bite you again in the future.

Thanks for @felkost for reporting this and @efiop for investigation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prihoda picture prihoda  路  3Comments

siddygups picture siddygups  路  3Comments

tc-ying picture tc-ying  路  3Comments

dmpetrov picture dmpetrov  路  3Comments

mdscruggs picture mdscruggs  路  3Comments